From 0280d96d2c42621a4364db58e53b6dbca4b8c708 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Fri, 24 Jan 2025 13:59:10 +0200 Subject: [PATCH] Sonar Fixes (#2232) Signed-off-by: Avgustin Marinov --- ...gmtAssignedDistributionSetRequestBody.java | 1 + .../model/MgmtAssignedTargetRequestBody.java | 1 + ...MgmtDistributionSetTagAssigmentResult.java | 1 + .../resource/MgmtDistributionSetMapper.java | 1 - .../resource/MgmtDistributionSetResource.java | 1 + .../MgmtDistributionSetTypeMapper.java | 24 +++---- .../resource/MgmtBasicAuthResourceTest.java | 2 +- .../rest/resource/MgmtContentTypeTest.java | 7 +- .../MgmtDistributionSetResourceTest.java | 20 +++--- .../MgmtDistributionSetTagResourceTest.java | 65 +++++++++---------- .../MgmtDistributionSetTypeResourceTest.java | 6 +- .../JpaSoftwareModuleManagement.java | 6 +- .../JpaTargetFilterQueryManagement.java | 1 + .../jpa/management/JpaTargetManagement.java | 16 +---- .../management/JpaTargetTagManagement.java | 4 +- .../management/JpaTargetTypeManagement.java | 1 + 16 files changed, 71 insertions(+), 86 deletions(-) diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java index e708f8370..9b06a8121 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java @@ -29,6 +29,7 @@ import lombok.experimental.Accessors; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) @Deprecated(forRemoval = true, since = "0.6.0") +@SuppressWarnings("java:S1133") // will be removed at some point public class MgmtAssignedDistributionSetRequestBody { @JsonProperty(value = "id", required = true) diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java index db7901a38..1ff62d5d9 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java @@ -29,6 +29,7 @@ import lombok.experimental.Accessors; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) @Deprecated(forRemoval = true, since = "0.6.0") +@SuppressWarnings("java:S1133") // will be removed at some point public class MgmtAssignedTargetRequestBody { @JsonProperty(required = true) diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java index 8d25dd6c1..4aa6b5c51 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java @@ -32,6 +32,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) @Deprecated(forRemoval = true, since = "0.6.0") +@SuppressWarnings("java:S1133") // will be removed at some point public class MgmtDistributionSetTagAssigmentResult { @JsonProperty diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index 90273c76e..4fc81b878 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index 765db157c..ee739cbad 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -87,6 +87,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { private final DistributionSetInvalidationManagement distributionSetInvalidationManagement; private final TenantConfigHelper tenantConfigHelper; + @SuppressWarnings("java:S107") MgmtDistributionSetResource( final SoftwareModuleManagement softwareModuleManagement, final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement, diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java index 61f26dc08..6ffb62ded 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java @@ -39,22 +39,19 @@ final class MgmtDistributionSetTypeMapper { } - static List smFromRequest(final EntityFactory entityFactory, - final Collection smTypesRest) { + static List smFromRequest(final EntityFactory entityFactory, final Collection smTypesRest) { if (smTypesRest == null) { return Collections.emptyList(); } - return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList()); + return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList(); } static List toListResponse(final Collection types) { if (types == null) { return Collections.emptyList(); } - - return new ResponseList<>( - types.stream().map(MgmtDistributionSetTypeMapper::toResponse).collect(Collectors.toList())); + return new ResponseList<>(types.stream().map(MgmtDistributionSetTypeMapper::toResponse).toList()); } static MgmtDistributionSetType toResponse(final DistributionSetType type) { @@ -82,19 +79,18 @@ final class MgmtDistributionSetTypeMapper { final MgmtDistributionSetTypeRequestBodyPost smsRest) { return entityFactory.distributionSetType().create().key(smsRest.getKey()).name(smsRest.getName()) .description(smsRest.getDescription()).colour(smsRest.getColour()) - .mandatory(getMandatoryModules(smsRest)).optional(getOptionalmodules(smsRest)); + .mandatory(getMandatoryModules(smsRest)).optional(getOptionalModules(smsRest)); } private static Collection getMandatoryModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) { - return Optional.ofNullable(smsRest.getMandatorymodules()).map( - modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList())) + return Optional.ofNullable(smsRest.getMandatorymodules()) + .map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList()) .orElse(Collections.emptyList()); } - private static Collection getOptionalmodules(final MgmtDistributionSetTypeRequestBodyPost smsRest) { - return Optional.ofNullable(smsRest.getOptionalmodules()).map( - modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList())) + private static Collection getOptionalModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) { + return Optional.ofNullable(smsRest.getOptionalmodules()) + .map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList()) .orElse(Collections.emptyList()); } - -} +} \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java index 35e4b3ee5..299e1e74d 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java @@ -109,7 +109,7 @@ class MgmtBasicAuthResourceTest { return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); } - private MockMvc withSecurityMock() throws Exception { + private MockMvc withSecurityMock() { return createMvcWebAppContext(webApplicationContext).build(); } diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtContentTypeTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtContentTypeTest.java index a6c43f126..fe62242be 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtContentTypeTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtContentTypeTest.java @@ -36,15 +36,14 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; /** - * With Spring Boot 2.2.x the default charset encoding became deprecated. In - * hawkBit we want to keep the old behavior for now and still return the charset - * in the response, which is achieved through enabling {@link Encoding} via - * properties. + * With Spring Boot 2.2.x the default charset encoding became deprecated. In hawkBit we want to keep the old behavior for now and still + * return the charset in the response, which is achieved through enabling {@link Encoding} via properties. */ @SpringBootTest(properties = { "server.servlet.encoding.charset=UTF-8", "server.servlet.encoding.force=true" }) @Import(HttpEncodingAutoConfiguration.class) @Feature("Component Tests - Management API") @Story("Response Content-Type") +@SuppressWarnings("java:S1874") // TODO for compatibility, to be checked if we really want to do that public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest { private final String dsName = "DS-รถ"; diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 5bc87dd3f..8dd3ed8e3 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -893,28 +893,28 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId()); + .hasToString("http://localhost/rest/v1/distributionsets/" + one.getId()); assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo(String.valueOf(one.getId())); + .hasToString(String.valueOf(one.getId())); assertThat( JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId()); + .hasToString("http://localhost/rest/v1/distributionsets/" + two.getId()); assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo(String.valueOf(two.getId())); + .hasToString(String.valueOf(two.getId())); assertThat( JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId()); + .hasToString("http://localhost/rest/v1/distributionsets/" + three.getId()); assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo(String.valueOf(three.getId())); + .hasToString(String.valueOf(three.getId())); // check in database assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(3); - assertThat(one.isRequiredMigrationStep()).isEqualTo(false); - assertThat(two.isRequiredMigrationStep()).isEqualTo(false); - assertThat(three.isRequiredMigrationStep()).isEqualTo(true); + assertThat(one.isRequiredMigrationStep()).isFalse(); + assertThat(two.isRequiredMigrationStep()).isFalse(); + assertThat(three.isRequiredMigrationStep()).isTrue(); assertThat(one.getCreatedAt()).isGreaterThanOrEqualTo(current); assertThat(two.getCreatedAt()).isGreaterThanOrEqualTo(current); @@ -938,7 +938,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr // check repository content assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); - assertThat(distributionSetManagement.count()).isEqualTo(0); + assertThat(distributionSetManagement.count()).isZero(); } @Test diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java index 1b89e4e60..ec29ded29 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java @@ -26,7 +26,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.stream.Collectors; import io.qameta.allure.Description; import io.qameta.allure.Feature; @@ -54,7 +53,7 @@ import org.springframework.test.web.servlet.ResultActions; @Feature("Component Tests - Management API") @Story("Distribution Set Tag Resource") -public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegrationTest { +class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegrationTest { private static final String DISTRIBUTIONSETTAGS_ROOT = "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/"; private static final Random RND = new Random(); @@ -62,7 +61,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verifies that a paged result list of DS tags reflects the content on the repository side.") @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) - public void getDistributionSetTags() throws Exception { + void getDistributionSetTags() throws Exception { final List tags = testdataFactory.createDistributionSetTags(2); final DistributionSetTag assigned = tags.get(0); final DistributionSetTag unassigned = tags.get(1); @@ -82,19 +81,16 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Handles the GET request of retrieving all distribution set tags based by parameter") - public void getDistributionSetTagsWithParameters() throws Exception { - final List tags = testdataFactory.createDistributionSetTags(2); - final DistributionSetTag assigned = tags.get(0); - final DistributionSetTag unassigned = tags.get(1); - mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING - + "?limit=10&sort=name:ASC&offset=0&q=name==DsTag")) + void getDistributionSetTagsWithParameters() throws Exception { + testdataFactory.createDistributionSetTags(2); + mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "?limit=10&sort=name:ASC&offset=0&q=name==DsTag")) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); } @Test @Description("Verifies that a paged result list of DS tags reflects the content on the repository side when filtered by distribution set id.") - public void getDistributionSetTagsByDistributionSetId() throws Exception { + void getDistributionSetTagsByDistributionSetId() throws Exception { final List tags = testdataFactory.createDistributionSetTags(2); final DistributionSetTag tag1 = tags.get(0); final DistributionSetTag tag2 = tags.get(1); @@ -133,7 +129,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verifies that a paged result list of DS tags reflects the content on the repository side when filtered by distribution set id field AND tag field.") - public void getDistributionSetTagsByDistributionSetIdAndTagDescription() throws Exception { + void getDistributionSetTagsByDistributionSetIdAndTagDescription() throws Exception { final List tags = testdataFactory.createDistributionSetTags(2); final DistributionSetTag tag1 = tags.get(0); final DistributionSetTag tag2 = tags.get(1); @@ -162,7 +158,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verifies that a single result of a DS tag reflects the content on the repository side.") @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) - public void getDistributionSetTag() throws Exception { + void getDistributionSetTag() throws Exception { final List tags = testdataFactory.createDistributionSetTags(2); final DistributionSetTag assigned = tags.get(0); @@ -180,7 +176,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verifies that created DS tags are stored in the repository as send to the API.") @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) - public void createDistributionSetTags() throws Exception { + void createDistributionSetTags() throws Exception { final Tag tagOne = entityFactory.tag().create().colour("testcol1").description("its a test1").name("thetest1") .build(); final Tag tagTwo = entityFactory.tag().create().colour("testcol2").description("its a test2").name("thetest2") @@ -212,7 +208,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagUpdatedEvent.class, count = 1) }) - public void updateDistributionSetTag() throws Exception { + void updateDistributionSetTag() throws Exception { final List tags = testdataFactory.createDistributionSetTags(1); final DistributionSetTag original = tags.get(0); @@ -241,7 +237,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagDeletedEvent.class, count = 1) }) - public void deleteDistributionSetTag() throws Exception { + void deleteDistributionSetTag() throws Exception { final List tags = testdataFactory.createDistributionSetTags(1); final DistributionSetTag original = tags.get(0); @@ -258,11 +254,11 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) - public void getAssignedDistributionSets() throws Exception { + void getAssignedDistributionSets() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final int setsAssigned = 5; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).toList(), tag.getId()); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")) .andDo(MockMvcResultPrinter.print()) @@ -278,12 +274,12 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) - public void getAssignedDistributionSetsWithPagingLimitRequestParameter() throws Exception { + void getAssignedDistributionSetsWithPagingLimitRequestParameter() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final int setsAssigned = 5; final int limitSize = 1; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).toList(), tag.getId()); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize))) @@ -300,14 +296,14 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) - public void getAssignedDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception { + void getAssignedDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final int setsAssigned = 5; final int offsetParam = 2; final int expectedSize = setsAssigned - offsetParam; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).toList(), tag.getId()); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)) @@ -325,7 +321,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetUpdatedEvent.class, count = 1) }) - public void assignDistributionSet() throws Exception { + void assignDistributionSet() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final DistributionSet set = testdataFactory.createDistributionSetsWithoutModules(1).get(0); @@ -335,8 +331,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt .andExpect(status().isOk()); final List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) - .containsOnly(set.getId()); + assertThat(updated.stream().map(DistributionSet::getId).toList()).containsOnly(set.getId()); } @Test @@ -345,20 +340,20 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetUpdatedEvent.class, count = 2) }) - public void assignDistributionSets() throws Exception { + void assignDistributionSets() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final List sets = testdataFactory.createDistributionSetsWithoutModules(2); mvc.perform( put(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") - .content(JsonBuilder.toArray(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()))) + .content(JsonBuilder.toArray(sets.stream().map(DistributionSet::getId).toList())) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); final List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) - .containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); + assertThat(updated.stream().map(DistributionSet::getId).toList()) + .containsAll(sets.stream().map(DistributionSet::getId).toList()); } @Test @@ -367,14 +362,14 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetUpdatedEvent.class, count = 3) }) - public void unassignDistributionSet() throws Exception { + void unassignDistributionSet() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final int setsAssigned = 2; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); final DistributionSet assigned = sets.get(0); final DistributionSet unassigned = sets.get(1); - distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).toList(), tag.getId()); mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" + unassigned.getId())) @@ -382,7 +377,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt .andExpect(status().isOk()); final List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) + assertThat(updated.stream().map(DistributionSet::getId).toList()) .containsOnly(assigned.getId()); } @@ -392,14 +387,14 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) - public void unassignDistributionSets() throws Exception { + void unassignDistributionSets() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final List sets = testdataFactory.createDistributionSetsWithoutModules(3); final DistributionSet assigned = sets.get(0); final DistributionSet unassigned0 = sets.get(1); final DistributionSet unassigned1 = sets.get(2); - distributionSetManagement.assignTag(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()), tag.getId()); + distributionSetManagement.assignTag(sets.stream().map(DistributionSet::getId).toList(), tag.getId()); mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .content(JsonBuilder.toArray(List.of(unassigned0.getId(), unassigned1.getId()))) @@ -408,7 +403,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt .andExpect(status().isOk()); final List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) + assertThat(updated.stream().map(DistributionSet::getId).toList()) .containsOnly(assigned.getId()); } @@ -417,7 +412,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2) }) - public void assignDistributionSetsNotFound() throws Exception { + void assignDistributionSetsNotFound() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final List sets = testdataFactory.createDistributionSetsWithoutModules(2).stream().map(DistributionSet::getId).toList(); final List missing = new ArrayList<>(); diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index 55de2bf2e..8a13cc67f 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -687,13 +687,13 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo("http://localhost/rest/v1/distributionsettypes/" + created1.getId()); + .hasToString("http://localhost/rest/v1/distributionsettypes/" + created1.getId()); assertThat( JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo("http://localhost/rest/v1/distributionsettypes/" + created2.getId()); + .hasToString("http://localhost/rest/v1/distributionsettypes/" + created2.getId()); assertThat( JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .isEqualTo("http://localhost/rest/v1/distributionsettypes/" + created3.getId()); + .hasToString("http://localhost/rest/v1/distributionsettypes/" + created3.getId()); assertThat(distributionSetTypeManagement.count()).isEqualTo(7); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java index 880638f81..a06d6646c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java @@ -44,10 +44,10 @@ import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleCreate; import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleMetadataCreate; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata_; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository; @@ -96,6 +96,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { private final VirtualPropertyReplacer virtualPropertyReplacer; private final Database database; + @SuppressWarnings("java:S107") public JpaSoftwareModuleManagement(final EntityManager entityManager, final DistributionSetRepository distributionSetRepository, final SoftwareModuleRepository softwareModuleRepository, @@ -506,8 +507,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { } private static Specification metadataBySoftwareModuleIdSpec(final long id) { - return (root, query, cb) -> cb - .equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), id); + return (root, query, cb) -> cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(AbstractJpaBaseEntity_.id), id); } private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java index 5fe6d4d31..c0ac2140e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java @@ -85,6 +85,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme private final AuditorAware auditorAware; private final Database database; + @SuppressWarnings("java:S107") public JpaTargetFilterQueryManagement(final TargetFilterQueryRepository targetFilterQueryRepository, final TargetManagement targetManagement, final VirtualPropertyReplacer virtualPropertyReplacer, final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java index d2f5b8ea0..f2fafcced 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java @@ -52,6 +52,7 @@ import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetCreate; import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetUpdate; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata_; @@ -104,31 +105,20 @@ import org.springframework.validation.annotation.Validated; public class JpaTargetManagement implements TargetManagement { private final EntityManager entityManager; - private final DistributionSetManagement distributionSetManagement; - private final QuotaManagement quotaManagement; - private final TargetRepository targetRepository; - private final TargetTypeRepository targetTypeRepository; - private final TargetMetadataRepository targetMetadataRepository; - private final RolloutGroupRepository rolloutGroupRepository; - private final TargetFilterQueryRepository targetFilterQueryRepository; - private final TargetTagRepository targetTagRepository; - private final EventPublisherHolder eventPublisherHolder; - private final TenantAware tenantAware; - private final VirtualPropertyReplacer virtualPropertyReplacer; - private final Database database; + @SuppressWarnings("java:S107") public JpaTargetManagement(final EntityManager entityManager, final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement, final TargetRepository targetRepository, final TargetTypeRepository targetTypeRepository, @@ -875,7 +865,7 @@ public class JpaTargetManagement implements TargetManagement { } private Specification metadataByTargetIdSpec(final Long targetId) { - return (root, query, cb) -> cb.equal(root.get(JpaTargetMetadata_.target).get(JpaTarget_.id), targetId); + return (root, query, cb) -> cb.equal(root.get(JpaTargetMetadata_.target).get(AbstractJpaBaseEntity_.id), targetId); } private List> buildSpecificationList(final FilterParams filterParams) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTagManagement.java index 63e160d7a..363d4581d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTagManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTagManagement.java @@ -24,8 +24,8 @@ import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper; import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_; import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.TargetTag; @@ -93,7 +93,7 @@ public class JpaTargetTagManagement implements TargetTagManagement { public void delete(final String targetTagName) { targetTagRepository.delete( targetTagRepository - .findOne(((root, query, cb) -> cb.equal(root.get(JpaTargetTag_.name), targetTagName))) + .findOne(((root, query, cb) -> cb.equal(root.get(AbstractJpaNamedEntity_.name), targetTagName))) .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagName))); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java index 0ce1e8b60..1866b533d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetTypeManagement.java @@ -217,6 +217,7 @@ public class JpaTargetTypeManagement implements TargetTypeManagement { return targetTypeRepository.save(type); } + @SuppressWarnings("java:S2201") // the idea is just to check for distribution set type existence private void assertDistributionSetTypeExists(final Long typeId) { distributionSetTypeRepository .findById(typeId)