diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java index 9fd49d778..7eca3566a 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java @@ -9,110 +9,57 @@ */ package org.eclipse.hawkbit.repository; -import java.util.Arrays; +import lombok.Getter; + import java.util.Collections; import java.util.List; /** * Sort and search fields for actions. */ +@Getter public enum ActionFields implements FieldNameProvider, FieldValueConverter { - /** - * The status field. - */ - STATUS("active"), - - /** - * The detailed action status - */ - DETAILSTATUS("status"), - - /** - * The last action status code - */ - LASTSTATUSCODE("lastActionStatusCode"), - - /** - * The id field. - */ ID("id"), - - /** - * The weight field. - */ + STATUS("active"), + DETAILSTATUS("status"), + LASTSTATUSCODE("lastActionStatusCode"), WEIGHT("weight"), - - /** - * The target field - */ - TARGET("target", TargetFields.ID.getFieldName(), TargetFields.NAME.getFieldName(), + TARGET("target", + TargetFields.ID.getFieldName(), TargetFields.NAME.getFieldName(), TargetFields.UPDATESTATUS.getFieldName(), TargetFields.IPADDRESS.getFieldName()), - - /** - * The distribution set field - */ - DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getFieldName(), + DISTRIBUTIONSET("distributionSet", + DistributionSetFields.ID.getFieldName(), DistributionSetFields.NAME.getFieldName(), DistributionSetFields.VERSION.getFieldName(), DistributionSetFields.TYPE.getFieldName()), - - /** - * The rollout field - */ ROLLOUT("rollout", RolloutFields.ID.getFieldName(), RolloutFields.NAME.getFieldName()), - - /** - * The rollout field - */ ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getFieldName(), RolloutGroupFields.NAME.getFieldName()), - - - /** - * The weight field. - */ EXTERNALREF("externalRef"); private static final String ACTIVE = "pending"; private static final String INACTIVE = "finished"; private final String fieldName; + private final List subEntityAttributes; - private List subEntityAttributes; - - private ActionFields(final String fieldName) { + ActionFields(final String fieldName) { this.fieldName = fieldName; this.subEntityAttributes = Collections.emptyList(); } - private ActionFields(final String fieldName, final String... subEntityAttributes) { + ActionFields(final String fieldName, final String... subEntityAttributes) { this.fieldName = fieldName; - this.subEntityAttributes = Arrays.asList(subEntityAttributes); - } - - @Override - public List getSubEntityAttributes() { - return subEntityAttributes; - } - - @Override - public String getFieldName() { - return fieldName; + this.subEntityAttributes = List.of(subEntityAttributes); } @Override public Object convertValue(final ActionFields e, final String value) { - if (STATUS == e) { - return convertStatusValue(value); - } - return value; + return STATUS == e ? convertStatusValue(value) : value; } @Override public String[] possibleValues(final ActionFields e) { - if (STATUS == e) { - return new String[] { ACTIVE, INACTIVE }; - } - return new String[0]; + return STATUS == e ? new String[] { ACTIVE, INACTIVE } : new String[0]; } private static Object convertStatusValue(final String value) { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionStatusFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionStatusFields.java index b25adc1da..6f79dbd5b 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionStatusFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionStatusFields.java @@ -9,33 +9,20 @@ */ 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 { - /** - * The id field. - */ ID("id"), - - /** - * The reportedAt field. - */ REPORTEDAT("createdAt"); private final String fieldName; - private ActionStatusFields(final String fieldName) { + ActionStatusFields(final String fieldName) { this.fieldName = fieldName; } - - @Override - public String getFieldName() { - return fieldName; - } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java index 3469482ce..54bdf0c8b 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFields.java @@ -9,8 +9,9 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + import java.util.AbstractMap.SimpleImmutableEntry; -import java.util.Arrays; import java.util.Collections; import java.util.List; 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 * REST API e.g. for sorting etc. - * - * - * - * */ +@Getter 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"), - /** - * 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"), - /** - * The metadata. - */ + NAME("name"), + 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")), - /** - * The valid field. - */ VALID("valid"); private final String fieldName; - private boolean mapField; - private Entry subEntityMapTuple; - + private final Entry subEntityMapTuple; private final List subEntityAttributes; - private DistributionSetFields(final String fieldName) { - this(fieldName, false, null, Collections.emptyList()); + DistributionSetFields(final String fieldName) { + this(fieldName, null, Collections.emptyList()); } - private DistributionSetFields(final String fieldName, final String... subEntityAttributes) { - this(fieldName, false, null, Arrays.asList(subEntityAttributes)); + DistributionSetFields(final String fieldName, final String... subEntityAttributes) { + this(fieldName, null, List.of(subEntityAttributes)); } - private DistributionSetFields(final String fieldName, final Entry subEntityMapTuple) { - this(fieldName, true, subEntityMapTuple, Collections.emptyList()); + DistributionSetFields(final String fieldName, final Entry subEntityMapTuple) { + this(fieldName, subEntityMapTuple, Collections.emptyList()); } - private DistributionSetFields(final String fieldName, final boolean mapField, - final Entry subEntityMapTuple, List subEntityAttributes) { + DistributionSetFields(final String fieldName, final Entry subEntityMapTuple, List subEntityAttributes) { this.fieldName = fieldName; - this.mapField = mapField; this.subEntityMapTuple = subEntityMapTuple; this.subEntityAttributes = subEntityAttributes; } - @Override - public List getSubEntityAttributes() { - return Collections.unmodifiableList(subEntityAttributes); - } - @Override public Optional> getSubEntityMapTuple() { return Optional.ofNullable(subEntityMapTuple); } - - @Override - public boolean isMap() { - return mapField; - } - - @Override - public String getFieldName() { - return fieldName; - } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetMetadataFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetMetadataFields.java index 1d022a286..2aca1ae88 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetMetadataFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetMetadataFields.java @@ -9,37 +9,25 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + /** * Sort fields for DistributionSetMetadata. - * - * - * - * */ +@Getter public enum DistributionSetMetadataFields implements FieldNameProvider { - /** - * The value field. - */ - VALUE("value"), - /** - * The key field. - */ - KEY("key"); + KEY("key"), + VALUE("value"); private final String fieldName; - private DistributionSetMetadataFields(final String fieldName) { + DistributionSetMetadataFields(final String fieldName) { this.fieldName = fieldName; } - @Override - public String getFieldName() { - return fieldName; - } - @Override public String identifierFieldName() { return KEY.getFieldName(); } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java index 2055024bb..2f8286023 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagFields.java @@ -9,62 +9,37 @@ */ package org.eclipse.hawkbit.repository; -import java.util.Arrays; +import lombok.Getter; + import java.util.Collections; import java.util.List; /** * 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 DistributionSet in order + * Additionally, here were added fields for DistributionSet in order * filtering over distribution set fields also. */ +@Getter public enum DistributionSetTagFields implements FieldNameProvider { - /** - * The id field. - */ + ID(TagFields.ID.getFieldName()), - - /** - * The name field. - */ NAME(TagFields.NAME.getFieldName()), - /** - * The description field. - */ DESCRIPTION(TagFields.DESCRIPTION.getFieldName()), - /** - * The controllerId field. - */ COLOUR(TagFields.COLOUR.getFieldName()), - - /** - * Distribution set fields - */ DISTRIBUTIONSET("assignedToDistributionSet", DistributionSetFields.ID.getFieldName(), DistributionSetFields.NAME.getFieldName()); private final String fieldName; - private final List subEntityAttributes; - private DistributionSetTagFields(final String fieldName) { + DistributionSetTagFields(final String fieldName) { this.fieldName = fieldName; this.subEntityAttributes = Collections.emptyList(); } - private DistributionSetTagFields(final String fieldName, final String... subEntityAttributes) { + DistributionSetTagFields(final String fieldName, final String... subEntityAttributes) { this.fieldName = fieldName; - this.subEntityAttributes = Arrays.asList(subEntityAttributes); - } - - @Override - public List getSubEntityAttributes() { - return Collections.unmodifiableList(subEntityAttributes); - } - - @Override - public String getFieldName() { - return fieldName; + this.subEntityAttributes = List.of(subEntityAttributes); } } \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeFields.java index 040681b39..c3e5f568a 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeFields.java @@ -9,42 +9,23 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + /** * Describing the fields of the DistributionSetType model which can be used in * the REST API e.g. for sorting etc. - * - * - * - * */ +@Getter public enum DistributionSetTypeFields implements FieldNameProvider { - /** - * The name field. - */ - NAME("name"), - /** - * The description field. - */ - DESCRIPTION("description"), - /** - * The type key field. - */ + ID("id"), KEY("key"), - - /** - * The id field. - */ - ID("id"); + NAME("name"), + DESCRIPTION("description"); private final String fieldName; - private DistributionSetTypeFields(final String fieldName) { + DistributionSetTypeFields(final String fieldName) { this.fieldName = fieldName; } - - @Override - public String getFieldName() { - return fieldName; - } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java index 6e6df3776..bc3f0ac6f 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldNameProvider.java @@ -15,7 +15,7 @@ import java.util.Map; import java.util.Map.Entry; 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 @@ -29,6 +29,7 @@ public interface FieldNameProvider { * Separator for the sub attributes */ String SUB_ATTRIBUTE_SEPARATOR = "."; + String SUB_ATTRIBUTE_SPLIT_REGEX = "\\" + SUB_ATTRIBUTE_SEPARATOR; /** * @return the string representation of the underlying persistence field @@ -39,39 +40,36 @@ public interface FieldNameProvider { /** * Returns the sub attributes * - * @param propertyFieldName - * the given field + * @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_SEPARATOR, 2); - // [0] fieldname |[1] keyname + final String[] subAttributes = propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX, 2); + // [0] field name | [1] key name 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(), mapKeyName }; } - return propertyFieldName.split("\\" + SUB_ATTRIBUTE_SEPARATOR); + return propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX); } /** * Contains the sub entity the given field. * - * @param propertyField - * the given field + * @param propertyField the given field * @return true contains false contains not */ default boolean containsSubEntityAttribute(final String propertyField) { - final List subEntityAttributes = getSubEntityAttributes(); if (subEntityAttributes.contains(propertyField)) { 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) { if (subAttribute.equalsIgnoreCase(propertyField)) { return true; @@ -102,7 +100,7 @@ public interface FieldNameProvider { * @return true is a map false is not a map */ default boolean isMap() { - return false; + return getSubEntityMapTuple().isPresent(); } /** @@ -113,4 +111,4 @@ public interface FieldNameProvider { default String identifierFieldName() { return "id"; } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java index 76d6fb383..f45850b4c 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/FieldValueConverter.java @@ -13,25 +13,19 @@ 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 {@link TargetAction#isActive()} boolean + * 'finished' values in rest queries to Action#isActive boolean * value. - * - * - * - * @param - * the enum parameter * + * @param the enum parameter */ public interface FieldValueConverter> { /** - * converts the given {@code value} into the representation to build a + * Converts the given {@code value} into the representation to build a * generic query. * - * @param e - * the enum to build the value for - * @param value - * the value in string representation + * @param e the enum to build the value for + * @param value the value in string representation * @return the converted object or {@code null} if conversation fails, if * given enum does not need to be converted the the unmodified * {@code value} is returned. @@ -41,10 +35,8 @@ public interface FieldValueConverter> { /** * returns the possible values associated with the given enum type. * - * @param e - * the enum type to retrieve the possible values + * @param e the enum type to retrieve the possible values * @return the possible values for a specific enum or {@code null} */ String[] possibleValues(final T e); - -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java index 961a3a6aa..e6ed9ef1f 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutFields.java @@ -9,60 +9,35 @@ */ package org.eclipse.hawkbit.repository; -import java.util.Arrays; +import lombok.Getter; + import java.util.Collections; import java.util.List; /** - * Describing the fields of the Rollout model which can be used in the REST API - * e.g. for sorting etc. - * + * Describing the fields of the Rollout model which can be used in the REST API e.g. for sorting etc. */ +@Getter public enum RolloutFields implements FieldNameProvider { - /** - * The name field. - */ - NAME("name"), - /** - * The description field. - */ - DESCRIPTION("description"), - /** - * The id field. - */ + ID("id"), - /** - * The status field. - */ + NAME("name"), + DESCRIPTION("description"), STATUS("status"), - /** - * The Distribution set field. - */ DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getFieldName(), DistributionSetFields.NAME.getFieldName(), DistributionSetFields.VERSION.getFieldName(), DistributionSetFields.TYPE.getFieldName()); private final String fieldName; - private final List subEntityAttributes; - private RolloutFields(final String fieldName) { + RolloutFields(final String fieldName) { this.fieldName = fieldName; this.subEntityAttributes = Collections.emptyList(); } - private RolloutFields(final String fieldName, final String... subEntityAttributes) { + RolloutFields(final String fieldName, final String... subEntityAttributes) { this.fieldName = fieldName; - this.subEntityAttributes = Arrays.asList(subEntityAttributes); + this.subEntityAttributes = List.of(subEntityAttributes); } - - @Override - public List getSubEntityAttributes() { - return Collections.unmodifiableList(subEntityAttributes); - } - - @Override - public String getFieldName() { - return fieldName; - } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupFields.java index 0c856239d..5b433e250 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupFields.java @@ -9,33 +9,21 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + /** - * Describing the fields of the RolloutGroup model which can be used in the REST - * API e.g. for sorting etc. - * + * Describing the fields of the RolloutGroup model which can be used in the REST API e.g. for sorting etc. */ +@Getter public enum RolloutGroupFields implements FieldNameProvider { - /** - * The name field. - */ + + ID("id"), NAME("name"), - /** - * The description field. - */ - DESCRIPTION("description"), - /** - * The id field. - */ - ID("id"); + DESCRIPTION("description"); private final String fieldName; - private RolloutGroupFields(final String fieldName) { + RolloutGroupFields(final String fieldName) { this.fieldName = fieldName; } - - @Override - public String getFieldName() { - return fieldName; - } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java index b87c1d178..f119266a3 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleFields.java @@ -9,60 +9,34 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Map.Entry; import java.util.Optional; /** - * Describing the fields of the SoftwareModule model which can be used in the - * REST API e.g. for sorting etc. - * - * - * - * + * Describing the fields of the SoftwareModule model which can be used in the REST API e.g. for sorting etc. */ +@Getter 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"), - /** - * The metadata. - */ + TYPE("type.key"), + NAME("name"), + DESCRIPTION("description"), + VERSION("version"), METADATA("metadata", new SimpleImmutableEntry<>("key", "value")); private final String fieldName; - private boolean mapField; private Entry subEntityMapTuple; - private SoftwareModuleFields(final String fieldName) { - this(fieldName, false, null); + SoftwareModuleFields(final String fieldName) { + this(fieldName, null); } - private SoftwareModuleFields(final String fieldName, final Entry subEntityMapTuple) { - this(fieldName, true, subEntityMapTuple); - } - - private SoftwareModuleFields(final String fieldName, final boolean mapField, - final Entry subEntityMapTuple) { + SoftwareModuleFields(final String fieldName, final Entry subEntityMapTuple) { this.fieldName = fieldName; - this.mapField = mapField; this.subEntityMapTuple = subEntityMapTuple; } @@ -70,14 +44,4 @@ public enum SoftwareModuleFields implements FieldNameProvider { public Optional> getSubEntityMapTuple() { return Optional.ofNullable(subEntityMapTuple); } - - @Override - public boolean isMap() { - return mapField; - } - - @Override - public String getFieldName() { - return fieldName; - } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleMetadataFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleMetadataFields.java index ad559d561..85229ce87 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleMetadataFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleMetadataFields.java @@ -9,40 +9,24 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + /** * Sort fields for SoftwareModuleMetadata. - * - * - * - * */ +@Getter public enum SoftwareModuleMetadataFields implements FieldNameProvider { - /** - * The value field. - */ - VALUE("value"), - /** - * The key field. - */ KEY("key"), - - /** - * The target visible field. - */ + VALUE("value"), TARGETVISIBLE("targetVisible"); private final String fieldName; - private SoftwareModuleMetadataFields(final String fieldName) { + SoftwareModuleMetadataFields(final String fieldName) { this.fieldName = fieldName; } - @Override - public String getFieldName() { - return fieldName; - } - @Override public String identifierFieldName() { return KEY.getFieldName(); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeFields.java index 734137481..699c8c5ae 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeFields.java @@ -9,44 +9,23 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + /** - * Describing the fields of the SoftwareModuleType model which can be used in - * the REST API e.g. for sorting etc. - * - * - * - * + * Describing the fields of the SoftwareModuleType model which can be used in the REST API e.g. for sorting etc. */ +@Getter 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"), - /** - * The max ds assignments field. - */ + KEY("key"), + NAME("name"), + DESCRIPTION("description"), MAXASSIGNMENTS("maxAssignments"); private final String fieldName; - private SoftwareModuleTypeFields(final String fieldName) { + SoftwareModuleTypeFields(final String fieldName) { this.fieldName = fieldName; } - - @Override - public String getFieldName() { - return fieldName; - } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java index 0d9c84a6a..ec394ba59 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java @@ -9,38 +9,22 @@ */ package org.eclipse.hawkbit.repository; -/** - * 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"), +import lombok.Getter; - /** - * 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"), - /** - * The description field. - */ DESCRIPTION("description"), - /** - * The controllerId field. - */ COLOUR("colour"); private final String fieldName; - private TagFields(final String fieldName) { + TagFields(final String fieldName) { this.fieldName = fieldName; } - - @Override - public String getFieldName() { - return fieldName; - } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java index 7197f6144..23d4966d5 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFields.java @@ -9,8 +9,9 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + import java.util.AbstractMap.SimpleImmutableEntry; -import java.util.Arrays; import java.util.Collections; import java.util.List; 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 * e.g. for sorting etc. - * */ +@Getter public enum TargetFields implements FieldNameProvider { - /** - * The controllerId field. - */ ID("controllerId"), - - /** - * The name field. - */ NAME("name"), - /** - * The description field. - */ DESCRIPTION("description"), - /** - * The createdAt field. - */ CREATEDAT("createdAt"), - /** - * The createdAt field. - */ LASTMODIFIEDAT("lastModifiedAt"), - /** - * The controllerId field. - */ CONTROLLERID("controllerId"), - /** - * The updateStatus field. - */ UPDATESTATUS("updateStatus"), - - /** - * The ip-address field. - */ IPADDRESS("address"), - - /** - * The attribute map of target info. - */ - ATTRIBUTE("controllerAttributes", true), - - /** - * distribution sets which is assigned to the target. - */ + ATTRIBUTE("controllerAttributes"), ASSIGNEDDS("assignedDistributionSet", "name", "version"), - - /** - * distribution sets which is installed on the target. - */ INSTALLEDDS("installedDistributionSet", "name", "version"), - - /** - * The tags field. - */ TAG("tags.name"), - - /** - * Last time the DDI or DMF client polled. - */ LASTCONTROLLERREQUESTAT("lastTargetQuery"), - - /** - * The metadata. - */ METADATA("metadata", new SimpleImmutableEntry<>("key", "value")), - - /** - * The target type. - */ TARGETTYPE("targetType", TargetTypeFields.KEY.getFieldName(), TargetTypeFields.NAME.getFieldName()); private final String fieldName; - private List subEntityAttribues; - private boolean mapField; - private Entry subEntityMapTuple; + private final List subEntityAttributes; + private final Entry subEntityMapTuple; - private TargetFields(final String fieldName) { - this(fieldName, false, Collections.emptyList(), null); + TargetFields(final String fieldName) { + this(fieldName, Collections.emptyList(), null); } - private TargetFields(final String fieldName, final boolean isMapField) { - this(fieldName, isMapField, Collections.emptyList(), null); + TargetFields(final String fieldName, final String... subEntityAttributes) { + this(fieldName, List.of(subEntityAttributes), null); } - private TargetFields(final String fieldName, final String... subEntityAttribues) { - this(fieldName, false, Arrays.asList(subEntityAttribues), null); + TargetFields(final String fieldName, final Entry subEntityMapTuple) { + this(fieldName, Collections.emptyList(), subEntityMapTuple); } - private TargetFields(final String fieldName, final Entry subEntityMapTuple) { - this(fieldName, true, Collections.emptyList(), subEntityMapTuple); - } - - private TargetFields(final String fieldName, final boolean mapField, final List subEntityAttribues, - final Entry subEntityMapTuple) { + TargetFields(final String fieldName, final List subEntityAttributes, final Entry subEntityMapTuple) { this.fieldName = fieldName; - this.mapField = mapField; - this.subEntityAttribues = subEntityAttribues; + this.subEntityAttributes = subEntityAttributes; this.subEntityMapTuple = subEntityMapTuple; } - @Override - public List getSubEntityAttributes() { - return subEntityAttribues; - } - @Override public Optional> getSubEntityMapTuple() { return Optional.ofNullable(subEntityMapTuple); @@ -134,11 +69,6 @@ public enum TargetFields implements FieldNameProvider { @Override public boolean isMap() { - return mapField; + return this == ATTRIBUTE || getSubEntityMapTuple().isPresent(); } - - @Override - public String getFieldName() { - return fieldName; - } -} +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java index 3bf9c1722..c90323bd4 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java @@ -9,55 +9,34 @@ */ package org.eclipse.hawkbit.repository; -import java.util.Arrays; +import lombok.Getter; + import java.util.Collections; import java.util.List; /** - * Describing the fields of the Target model which can be used in the REST API - * e.g. for sorting etc. - * + * Describing the fields of the Target model which can be used in the REST API e.g. for sorting etc. */ +@Getter public enum TargetFilterQueryFields implements FieldNameProvider { - /** - * The id field. - */ ID("id"), - - /** - * The name field. - */ NAME("name"), - - /** - * Distribution set for auto-assignment. - */ AUTOASSIGNDISTRIBUTIONSET("autoAssignDistributionSet", "name", "version"); private final String fieldName; private List subEntityAttributes; - private TargetFilterQueryFields(final String fieldName) { + TargetFilterQueryFields(final String fieldName) { this(fieldName, Collections.emptyList()); } - private TargetFilterQueryFields(final String fieldName, final String... subEntityAttribues) { - this(fieldName, Arrays.asList(subEntityAttribues)); + TargetFilterQueryFields(final String fieldName, final String... subEntityAttribues) { + this(fieldName, List.of(subEntityAttribues)); } - private TargetFilterQueryFields(final String fieldName, final List subEntityAttribues) { + TargetFilterQueryFields(final String fieldName, final List subEntityAttribues) { this.fieldName = fieldName; this.subEntityAttributes = subEntityAttribues; } - - @Override - public String getFieldName() { - return fieldName; - } - - @Override - public List getSubEntityAttributes() { - return subEntityAttributes; - } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetMetadataFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetMetadataFields.java index 137cbdcb9..a487ddbcf 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetMetadataFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetMetadataFields.java @@ -9,32 +9,23 @@ */ package org.eclipse.hawkbit.repository; +import lombok.Getter; + /** * Sort fields for TargetMetadata. - * */ +@Getter public enum TargetMetadataFields implements FieldNameProvider { - /** - * The value field. - */ - VALUE("value"), - /** - * The key field. - */ - KEY("key"); + KEY("key"), + VALUE("value"); private final String fieldName; - private TargetMetadataFields(final String fieldName) { + TargetMetadataFields(final String fieldName) { this.fieldName = fieldName; } - @Override - public String getFieldName() { - return fieldName; - } - @Override public String identifierFieldName() { return KEY.getFieldName(); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java index a16766021..79da07972 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTagFields.java @@ -9,29 +9,18 @@ */ package org.eclipse.hawkbit.repository; -/** - * 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()), +import lombok.Getter; - /** - * 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()), - /** - * The description field. - */ DESCRIPTION(TagFields.DESCRIPTION.getFieldName()), - /** - * The controllerId field. - */ COLOUR(TagFields.COLOUR.getFieldName()); private final String fieldName; @@ -39,9 +28,4 @@ public enum TargetTagFields implements FieldNameProvider { TargetTagFields(final String fieldName) { this.fieldName = fieldName; } - - @Override - public String getFieldName() { - return fieldName; - } } \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTypeFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTypeFields.java index 97fc98584..090486c26 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTypeFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetTypeFields.java @@ -9,37 +9,22 @@ */ package org.eclipse.hawkbit.repository; -/** - * 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"), +import lombok.Getter; - /** - * The id field. - */ - ID("id"); +/** + * Describing the fields of the TargetType model which can be used in the REST API + */ +@Getter +public enum TargetTypeFields implements FieldNameProvider { + + ID("id"), + KEY("key"), + NAME("name"), + DESCRIPTION("description"); private final String fieldName; TargetTypeFields(final String fieldName) { this.fieldName = fieldName; } - - @Override - public String getFieldName() { - return fieldName; - } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterUnsupportedFieldException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterUnsupportedFieldException.java index 6aff2b55b..8916f77d9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterUnsupportedFieldException.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterUnsupportedFieldException.java @@ -12,19 +12,14 @@ package org.eclipse.hawkbit.repository.exception; import org.eclipse.hawkbit.exception.AbstractServerRtException; 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 - * search parameter. - * - * - * - * + * Exception used by the REST API in case of invalid field name in the rsql search parameter. */ public class RSQLParameterUnsupportedFieldException extends AbstractServerRtException { - /** - * - */ + @Serial private static final long serialVersionUID = 1L; /** @@ -35,12 +30,21 @@ public class RSQLParameterUnsupportedFieldException extends AbstractServerRtExce 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 * {@link SpServerError#SP_REST_RSQL_PARAM_INVALID_FIELD} error. * - * @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 * that the cause is nonexistent or unknown.) */ @@ -52,10 +56,8 @@ public class RSQLParameterUnsupportedFieldException extends AbstractServerRtExce * Creates a new RSQLParameterUnsupportedFieldException with * {@link SpServerError#SP_REST_RSQL_PARAM_INVALID_FIELD} error. * - * @param message - * the message of the exception - * @param cause - * the cause (which is saved for later retrieval by the + * @param message the message of the exception + * @param cause the cause (which is saved for later retrieval by the * getCause() method). (A null value is permitted, and indicates * that the cause is nonexistent or unknown.) */ diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractFieldNameRSQLVisitor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractFieldNameRSQLVisitor.java index 48130fe08..540034bb0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractFieldNameRSQLVisitor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractFieldNameRSQLVisitor.java @@ -31,11 +31,8 @@ public abstract class AbstractFieldNameRSQLVisitor & FieldName } protected A getFieldEnumByName(final ComparisonNode node) { - String enumName = node.getSelector(); - final String[] graph = enumName.split("\\" + FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR); - if (graph.length != 0) { - enumName = graph[0]; - } + final String[] graph = node.getSelector().split(FieldNameProvider.SUB_ATTRIBUTE_SPLIT_REGEX); + final String enumName = graph.length == 0 ? node.getSelector() : graph[0]; log.debug("get field identifier by name {} of enum type {}", enumName, fieldNameProvider); try { return Enum.valueOf(fieldNameProvider, enumName.toUpperCase()); @@ -45,25 +42,21 @@ public abstract class AbstractFieldNameRSQLVisitor & FieldName } protected String getAndValidatePropertyFieldName(final A propertyEnum, final ComparisonNode node) { - - final String[] graph = propertyEnum.getSubAttributes(node.getSelector()); - - validateMapParameter(propertyEnum, node, graph); + final String[] subAttributes = propertyEnum.getSubAttributes(node.getSelector()); + validateMapParameter(propertyEnum, node, subAttributes); // sub entity need minimum 1 dot - if (!propertyEnum.getSubEntityAttributes().isEmpty() && graph.length < 2) { + if (!propertyEnum.getSubEntityAttributes().isEmpty() && subAttributes.length < 2) { throw createRSQLParameterUnsupportedException(node, null); } final StringBuilder fieldNameBuilder = new StringBuilder(propertyEnum.getFieldName()); - - for (int i = 1; i < graph.length; i++) { - - final String propertyField = getFormattedSubEntityAttribute(propertyEnum ,graph[i]); + for (int i = 1; i < subAttributes.length; i++) { + final String propertyField = getFormattedSubEntityAttribute(propertyEnum ,subAttributes[i]); fieldNameBuilder.append(FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR).append(propertyField); // the key of map is not in the graph - if (propertyEnum.isMap() && graph.length == (i + 1)) { + if (propertyEnum.isMap() && subAttributes.length == (i + 1)) { continue; } @@ -75,30 +68,26 @@ public abstract class AbstractFieldNameRSQLVisitor & FieldName 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()) { return; - } if (!propertyEnum.getSubEntityAttributes().isEmpty()) { 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 - final int minAttributeForMap = 2; - if (graph.length != minAttributeForMap) { - throw new RSQLParameterUnsupportedFieldException("The syntax of the given map search parameter field {" - + node.getSelector() + "} is wrong. Syntax is: fieldname.keyname", new Exception()); + if (subAttributes.length != 2) { + throw new RSQLParameterUnsupportedFieldException("The syntax of the given map search parameter field {" + + node.getSelector() + "} is wrong. Syntax is: ."); } } /** - * @param node - * current processing node - * @param rootException - * in case there is a cause otherwise {@code null} + * @param node current processing node + * @param rootException in case there is a cause otherwise {@code null} * @return Exception with prepared message extracted from the comparison node. */ protected RSQLParameterUnsupportedFieldException createRSQLParameterUnsupportedException( @@ -110,20 +99,20 @@ public abstract class AbstractFieldNameRSQLVisitor & FieldName } private String getFormattedSubEntityAttribute(final A propertyEnum, final String propertyField) { - return propertyEnum.getSubEntityAttributes().stream().filter(attr -> attr.equalsIgnoreCase(propertyField)) - .findFirst().orElse(propertyField); + return propertyEnum.getSubEntityAttributes().stream() + .filter(attr -> attr.equalsIgnoreCase(propertyField)) + .findFirst().orElse(propertyField); } private List getExpectedFieldList() { final List expectedFieldList = Arrays.stream(fieldNameProvider.getEnumConstants()) .filter(enumField -> enumField.getSubEntityAttributes().isEmpty()).map(enumField -> { final String enumFieldName = enumField.name().toLowerCase(); - if (enumField.isMap()) { return enumFieldName + FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR + "keyName"; + } else { + return enumFieldName; } - - return enumFieldName; }).collect(Collectors.toList()); final List expectedSubFieldList = Arrays.stream(fieldNameProvider.getEnumConstants()) @@ -131,11 +120,11 @@ public abstract class AbstractFieldNameRSQLVisitor & FieldName final List subEntity = enumField .getSubEntityAttributes().stream().map(fieldName -> enumField.name().toLowerCase() + FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR + fieldName) - .collect(Collectors.toList()); + .toList(); return subEntity.stream(); - }).collect(Collectors.toList()); + }).toList(); expectedFieldList.addAll(expectedSubFieldList); return expectedFieldList; } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java index 644316e0b..b1eec8406 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java @@ -56,7 +56,6 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle { @Override public ValidationOracleContext suggest(final String rsqlQuery, final int cursorPosition) { - final List expectedTokens = new ArrayList<>(); final ValidationOracleContext context = new ValidationOracleContext(); context.setSyntaxError(true); @@ -92,8 +91,8 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle { final Collection tokenImages = TokenDescription.getTokenImage(TokenDescription.LOGICAL_OP); final List logicalOps = new ArrayList<>(tokenImages.size()); for (final String tokenImage : tokenImages) { - logicalOps.add(new SuggestToken(currentQueryLength, currentQueryLength + tokenImage.length(), null, - tokenImage)); + logicalOps.add( + new SuggestToken(currentQueryLength, currentQueryLength + tokenImage.length(), null, tokenImage)); } return logicalOps; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLParserValidationOracleTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLParserValidationOracleTest.java index a6b0eaa5a..b2c2a4f43 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLParserValidationOracleTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLParserValidationOracleTest.java @@ -18,6 +18,7 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle; +import org.eclipse.hawkbit.repository.rsql.SuggestToken; import org.eclipse.hawkbit.repository.rsql.ValidationOracleContext; import org.junit.jupiter.api.Test; 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=", "=out=" }; 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[] NAME_VERSION_SUGGESTIONS = new String[] { "name", "version" }; @@ -73,10 +74,9 @@ public class RSQLParserValidationOracleTest extends AbstractJpaIntegrationTest { } private List getSuggestions(final String rsqlQuery) { - final ValidationOracleContext suggest = rsqlValidationOracle.suggest(rsqlQuery, -1); - final List currentSuggestions = suggest.getSuggestionContext().getSuggestions().stream() - .map(suggestion -> suggestion.getSuggestion()).collect(Collectors.toList()); - return currentSuggestions; + return rsqlValidationOracle + .suggest(rsqlQuery, -1).getSuggestionContext().getSuggestions().stream() + .map(SuggestToken::getSuggestion) + .collect(Collectors.toList()); } - -} +} \ No newline at end of file