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 48d9f052d..ddd763d5e 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,6 +9,9 @@ package org.eclipse.hawkbit.repository; import java.util.AbstractMap.SimpleImmutableEntry; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Map.Entry; import java.util.Optional; @@ -49,22 +52,22 @@ public enum DistributionSetFields implements FieldNameProvider { * 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. */ METADATA("metadata", new SimpleImmutableEntry<>("key", "value")), - /** * The valid field. */ @@ -74,19 +77,31 @@ public enum DistributionSetFields implements FieldNameProvider { private boolean mapField; private Entry subEntityMapTuple; + private final List subEntityAttributes; + private DistributionSetFields(final String fieldName) { - this(fieldName, false, null); + this(fieldName, false, null, Collections.emptyList()); + } + + private DistributionSetFields(final String fieldName, final String... subEntityAttributes) { + this(fieldName, false, null, Arrays.asList(subEntityAttributes)); } private DistributionSetFields(final String fieldName, final Entry subEntityMapTuple) { - this(fieldName, true, subEntityMapTuple); + this(fieldName, true, subEntityMapTuple, Collections.emptyList()); } private DistributionSetFields(final String fieldName, final boolean mapField, - final Entry subEntityMapTuple) { + 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 diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java index 0dedd3336..b69b6b033 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java @@ -13,13 +13,16 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; +import java.util.Collections; import org.eclipse.hawkbit.repository.DistributionSetFields; +import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.test.util.TestdataFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,11 +39,14 @@ import io.qameta.allure.Story; public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { private DistributionSet ds; + private SoftwareModule sm; @BeforeEach public void setupBeforeTest() { - ds = testdataFactory.createDistributionSet("DS"); + sm = testdataFactory.createSoftwareModuleApp("SM"); + + ds = testdataFactory.createDistributionSet(Collections.singletonList(sm),"DS"); ds = distributionSetManagement.update(entityFactory.distributionSet().update(ds.getId()).description("DS")); createDistributionSetMetadata(ds.getId(), entityFactory.generateDsMetadata("metaKey", "metaValue")); @@ -92,6 +98,16 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { assertRSQLQuery(DistributionSetFields.NAME.name() + "=out=(DS,notexist)", 4); } + @Test + @Description("Test filter distribution set by assigned software module") + public void testFilterBySoftwareModule() { + assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==" + sm.getName(), 1); + assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "==" + sm.getId(), 1); + assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==noExist", 0); + assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=in=(" + sm.getId() + ", noExist)", 1); + assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=out=(" + sm.getId() + ", noExist)", 4); + } + @Test @Description("Test filter distribution set by description") public void testFilterByParameterDescription() { @@ -121,14 +137,14 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by complete property") public void testFilterByAttributeComplete() { - assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==true", 4); + assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==true", 3); try { assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==noExist*", 0); fail("Expected RSQLParameterSyntaxException"); } catch (final RSQLParameterSyntaxException e) { } - assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=in=(true)", 4); - assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=out=(true)", 1); + assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=in=(true)", 3); + assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=out=(true)", 2); } @Test