From 6379e93c5e8de6778f4b413572301701322a43e9 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 9 Mar 2016 19:34:28 +0100 Subject: [PATCH 1/3] Fixed max assignments filter on sw module type --- .../java/org/eclipse/hawkbit/repository/FieldNameProvider.java | 2 +- .../eclipse/hawkbit/repository/SoftwareModuleTypeFields.java | 2 +- .../repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 eef36f552..fb9166529 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 @@ -20,7 +20,7 @@ import java.util.Map; */ public interface FieldNameProvider { /** - * Seperator for the sub attributes + * Separator for the sub attributes */ public static final String SUB_ATTRIBUTE_SEPERATOR = "."; 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 beb46a9d7..68e4f4427 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 @@ -36,7 +36,7 @@ public enum SoftwareModuleTypeFields implements FieldNameProvider { /** * The max ds assignments field. */ - MAX("maxAssignments"); + MAXASSIGNMENTS("maxAssignments"); private final String fieldName; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java index 12f4005ac..268bddf50 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java @@ -55,7 +55,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest { @Test @Description("Test filter software module test type by max") public void testFilterByMaxAssignment() { - assertRSQLQuery(SoftwareModuleTypeFields.MAX.name() + "==1", 3); + assertRSQLQuery(SoftwareModuleTypeFields.MAXASSIGNMENTS.name() + "==1", 3); } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { From 462419b2f9fee776c860acf0f4528915c7200392 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 9 Mar 2016 19:53:19 +0100 Subject: [PATCH 2/3] Fixed broken sorting for sm type and ds type --- .../resource/DistributionSetTypeResource.java | 2 +- .../hawkbit/rest/resource/PagingUtility.java | 24 +++++++++++ .../resource/SoftwareModuleTypeResource.java | 2 +- .../DistributionSetTypeResourceTest.java | 37 +++++++++++++++++ .../SoftwareModuleTypeResourceTest.java | 40 +++++++++++++++++++ 5 files changed, 103 insertions(+), 2 deletions(-) diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java index 700ef3d96..a5c8544fb 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java @@ -64,7 +64,7 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); - final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam); + final Sort sorting = PagingUtility.sanitizeDistributionSetTypeSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java index 4fb854608..789f3a952 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java @@ -12,10 +12,12 @@ import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; +import org.eclipse.hawkbit.repository.DistributionSetTypeFields; import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutGroupFields; import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; +import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; import org.eclipse.hawkbit.repository.TargetFields; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; @@ -69,6 +71,17 @@ public final class PagingUtility { return sorting; } + static Sort sanitizeSoftwareModuleTypeSortParam(final String sortParam) { + final Sort sorting; + if (sortParam != null) { + sorting = new Sort(SortUtility.parse(SoftwareModuleTypeFields.class, sortParam)); + } else { + // default sort + sorting = new Sort(Direction.ASC, SoftwareModuleTypeFields.NAME.getFieldName()); + } + return sorting; + } + static Sort sanitizeDistributionSetSortParam(final String sortParam) { final Sort sorting; if (sortParam != null) { @@ -80,6 +93,17 @@ public final class PagingUtility { return sorting; } + static Sort sanitizeDistributionSetTypeSortParam(final String sortParam) { + final Sort sorting; + if (sortParam != null) { + sorting = new Sort(SortUtility.parse(DistributionSetTypeFields.class, sortParam)); + } else { + // default sort + sorting = new Sort(Direction.ASC, DistributionSetTypeFields.NAME.getFieldName()); + } + return sorting; + } + static Sort sanitizeActionSortParam(final String sortParam) { final Sort sorting; if (sortParam != null) { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java index c989bf6ad..4259dcc90 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java @@ -48,7 +48,7 @@ public class SoftwareModuleTypeResource implements SoftwareModuleTypeRestApi { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); - final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam); + final Sort sorting = PagingUtility.sanitizeSoftwareModuleTypeSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java index 78f4f741e..9f3d2a89d 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java @@ -89,6 +89,43 @@ public class DistributionSetTypeResourceTest extends AbstractIntegrationTest { .andExpect(jsonPath("$total", equalTo(4))); } + @Test + @WithUser(principal = "uploadTester", allSpPermissions = true) + @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with sorting by KEY.") + public void getDistributionSetTypesSortedByKey() throws Exception { + + DistributionSetType testType = distributionSetManagement + .createDistributionSetType(new DistributionSetType("zzzzz", "TestName123", "Desc123")); + testType.setDescription("Desc1234"); + testType = distributionSetManagement.updateDistributionSetType(testType); + + // descending + mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) + .param(RestConstants.REQUEST_PARAMETER_SORTING, "KEY:DESC")).andDo(MockMvcResultPrinter.print()) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$content.[0].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$content.[0].name", equalTo("TestName123"))) + .andExpect(jsonPath("$content.[0].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$content.[0].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[0].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$content.[0].key", equalTo("zzzzz"))).andExpect(jsonPath("$total", equalTo(4))); + + // ascending + mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) + .param(RestConstants.REQUEST_PARAMETER_SORTING, "KEY:ASC")).andDo(MockMvcResultPrinter.print()) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$content.[3].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$content.[3].name", equalTo("TestName123"))) + .andExpect(jsonPath("$content.[3].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$content.[3].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[3].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$content.[3].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$content.[3].key", equalTo("zzzzz"))).andExpect(jsonPath("$total", equalTo(4))); + } + @Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes POST requests.") diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java index fefe2a440..a85e25bed 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java @@ -90,6 +90,46 @@ public class SoftwareModuleTypeResourceTest extends AbstractIntegrationTest { .andExpect(jsonPath("$total", equalTo(4))); } + @Test + @WithUser(principal = "uploadTester", allSpPermissions = true) + @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with sorting by MAXASSIGNMENTS field.") + public void getSoftwareModuleTypesSortedByMaxAssignments() throws Exception { + SoftwareModuleType testType = softwareManagement + .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + testType.setDescription("Desc1234"); + testType = softwareManagement.updateSoftwareModuleType(testType); + + // descending + mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) + .param(RestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:DESC")) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$content.[0].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$content.[0].name", equalTo("TestName123"))) + .andExpect(jsonPath("$content.[0].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$content.[0].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[0].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$content.[0].maxAssignments", equalTo(5))) + .andExpect(jsonPath("$content.[0].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); + + // ascending + mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) + .param(RestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:ASC")) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$content.[3].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$content.[3].name", equalTo("TestName123"))) + .andExpect(jsonPath("$content.[3].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$content.[3].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[3].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$content.[3].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$content.[3].maxAssignments", equalTo(5))) + .andExpect(jsonPath("$content.[3].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); + } + @Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes POST requests.") From 44ce503a28441a40b289b41932751c473f5be488 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 10 Mar 2016 14:10:15 +0100 Subject: [PATCH 3/3] Introduced direct return of default --- .../hawkbit/rest/resource/PagingUtility.java | 117 +++++++----------- 1 file changed, 42 insertions(+), 75 deletions(-) diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java index 789f3a952..ac45796e5 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java @@ -50,125 +50,92 @@ public final class PagingUtility { } static Sort sanitizeTargetSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(TargetFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, TargetFields.NAME.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, TargetFields.NAME.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(TargetFields.class, sortParam)); } static Sort sanitizeSoftwareModuleSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(SoftwareModuleFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, SoftwareModuleFields.NAME.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, SoftwareModuleFields.NAME.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(SoftwareModuleFields.class, sortParam)); } static Sort sanitizeSoftwareModuleTypeSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(SoftwareModuleTypeFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, SoftwareModuleTypeFields.NAME.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, SoftwareModuleTypeFields.NAME.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(SoftwareModuleTypeFields.class, sortParam)); } static Sort sanitizeDistributionSetSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(DistributionSetFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, DistributionSetFields.NAME.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, DistributionSetFields.NAME.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(DistributionSetFields.class, sortParam)); } static Sort sanitizeDistributionSetTypeSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(DistributionSetTypeFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, DistributionSetTypeFields.NAME.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, DistributionSetTypeFields.NAME.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(DistributionSetTypeFields.class, sortParam)); } static Sort sanitizeActionSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(ActionFields.class, sortParam)); - } else { + if (sortParam == null) { // default sort is DESC in case of action to match behavior // of management UI (last entry on top) - sorting = new Sort(Direction.DESC, ActionFields.ID.getFieldName()); + return new Sort(Direction.DESC, ActionFields.ID.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(ActionFields.class, sortParam)); } static Sort sanitizeActionStatusSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(ActionStatusFields.class, sortParam)); - } else { + if (sortParam == null) { // default sort is DESC in case of action status to match behavior // of management UI (last entry on top) - sorting = new Sort(Direction.DESC, ActionStatusFields.ID.getFieldName()); + return new Sort(Direction.DESC, ActionStatusFields.ID.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(ActionStatusFields.class, sortParam)); } static Sort sanitizeDistributionSetMetadataSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(DistributionSetMetadataFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, DistributionSetMetadataFields.KEY.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, DistributionSetMetadataFields.KEY.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(DistributionSetMetadataFields.class, sortParam)); } static Sort sanitizeSoftwareModuleMetadataSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(SoftwareModuleMetadataFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, SoftwareModuleMetadataFields.KEY.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, SoftwareModuleMetadataFields.KEY.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(SoftwareModuleMetadataFields.class, sortParam)); } static Sort sanitizeRolloutSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(RolloutFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, RolloutFields.NAME.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, RolloutFields.NAME.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(RolloutFields.class, sortParam)); } static Sort sanitizeRolloutGroupSortParam(final String sortParam) { - final Sort sorting; - if (sortParam != null) { - sorting = new Sort(SortUtility.parse(RolloutGroupFields.class, sortParam)); - } else { - // default sort - sorting = new Sort(Direction.ASC, RolloutGroupFields.NAME.getFieldName()); + if (sortParam == null) { + // default + return new Sort(Direction.ASC, RolloutGroupFields.NAME.getFieldName()); } - return sorting; + return new Sort(SortUtility.parse(RolloutGroupFields.class, sortParam)); } }