Sonar Fixes (#2232)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-24 13:59:10 +02:00
committed by GitHub
parent 51054bdd2f
commit 0280d96d2c
16 changed files with 71 additions and 86 deletions

View File

@@ -29,6 +29,7 @@ import lombok.experimental.Accessors;
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@Deprecated(forRemoval = true, since = "0.6.0") @Deprecated(forRemoval = true, since = "0.6.0")
@SuppressWarnings("java:S1133") // will be removed at some point
public class MgmtAssignedDistributionSetRequestBody { public class MgmtAssignedDistributionSetRequestBody {
@JsonProperty(value = "id", required = true) @JsonProperty(value = "id", required = true)

View File

@@ -29,6 +29,7 @@ import lombok.experimental.Accessors;
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@Deprecated(forRemoval = true, since = "0.6.0") @Deprecated(forRemoval = true, since = "0.6.0")
@SuppressWarnings("java:S1133") // will be removed at some point
public class MgmtAssignedTargetRequestBody { public class MgmtAssignedTargetRequestBody {
@JsonProperty(required = true) @JsonProperty(required = true)

View File

@@ -32,6 +32,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@Deprecated(forRemoval = true, since = "0.6.0") @Deprecated(forRemoval = true, since = "0.6.0")
@SuppressWarnings("java:S1133") // will be removed at some point
public class MgmtDistributionSetTagAssigmentResult { public class MgmtDistributionSetTagAssigmentResult {
@JsonProperty @JsonProperty

View File

@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

View File

@@ -87,6 +87,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
private final DistributionSetInvalidationManagement distributionSetInvalidationManagement; private final DistributionSetInvalidationManagement distributionSetInvalidationManagement;
private final TenantConfigHelper tenantConfigHelper; private final TenantConfigHelper tenantConfigHelper;
@SuppressWarnings("java:S107")
MgmtDistributionSetResource( MgmtDistributionSetResource(
final SoftwareModuleManagement softwareModuleManagement, final SoftwareModuleManagement softwareModuleManagement,
final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement, final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement,

View File

@@ -39,22 +39,19 @@ final class MgmtDistributionSetTypeMapper {
} }
static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory, static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory, final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
if (smTypesRest == null) { if (smTypesRest == null) {
return Collections.emptyList(); 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<MgmtDistributionSetType> toListResponse(final Collection<DistributionSetType> types) { static List<MgmtDistributionSetType> toListResponse(final Collection<DistributionSetType> types) {
if (types == null) { if (types == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return new ResponseList<>(types.stream().map(MgmtDistributionSetTypeMapper::toResponse).toList());
return new ResponseList<>(
types.stream().map(MgmtDistributionSetTypeMapper::toResponse).collect(Collectors.toList()));
} }
static MgmtDistributionSetType toResponse(final DistributionSetType type) { static MgmtDistributionSetType toResponse(final DistributionSetType type) {
@@ -82,19 +79,18 @@ final class MgmtDistributionSetTypeMapper {
final MgmtDistributionSetTypeRequestBodyPost smsRest) { final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return entityFactory.distributionSetType().create().key(smsRest.getKey()).name(smsRest.getName()) return entityFactory.distributionSetType().create().key(smsRest.getKey()).name(smsRest.getName())
.description(smsRest.getDescription()).colour(smsRest.getColour()) .description(smsRest.getDescription()).colour(smsRest.getColour())
.mandatory(getMandatoryModules(smsRest)).optional(getOptionalmodules(smsRest)); .mandatory(getMandatoryModules(smsRest)).optional(getOptionalModules(smsRest));
} }
private static Collection<Long> getMandatoryModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) { private static Collection<Long> getMandatoryModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return Optional.ofNullable(smsRest.getMandatorymodules()).map( return Optional.ofNullable(smsRest.getMandatorymodules())
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList())) .map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList())
.orElse(Collections.emptyList()); .orElse(Collections.emptyList());
} }
private static Collection<Long> getOptionalmodules(final MgmtDistributionSetTypeRequestBodyPost smsRest) { private static Collection<Long> getOptionalModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return Optional.ofNullable(smsRest.getOptionalmodules()).map( return Optional.ofNullable(smsRest.getOptionalmodules())
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList())) .map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList())
.orElse(Collections.emptyList()); .orElse(Collections.emptyList());
} }
} }

View File

@@ -109,7 +109,7 @@ class MgmtBasicAuthResourceTest {
return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes());
} }
private MockMvc withSecurityMock() throws Exception { private MockMvc withSecurityMock() {
return createMvcWebAppContext(webApplicationContext).build(); return createMvcWebAppContext(webApplicationContext).build();
} }

View File

@@ -36,15 +36,14 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
/** /**
* With Spring Boot 2.2.x the default charset encoding became deprecated. In * 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
* hawkBit we want to keep the old behavior for now and still return the charset * return the charset in the response, which is achieved through enabling {@link Encoding} via properties.
* 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" }) @SpringBootTest(properties = { "server.servlet.encoding.charset=UTF-8", "server.servlet.encoding.force=true" })
@Import(HttpEncodingAutoConfiguration.class) @Import(HttpEncodingAutoConfiguration.class)
@Feature("Component Tests - Management API") @Feature("Component Tests - Management API")
@Story("Response Content-Type") @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 { public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {
private final String dsName = "DS-ö"; private final String dsName = "DS-ö";

View File

@@ -893,28 +893,28 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assertThat( assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) 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()) assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(one.getId())); .hasToString(String.valueOf(one.getId()));
assertThat( assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) 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()) assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(two.getId())); .hasToString(String.valueOf(two.getId()));
assertThat( assertThat(
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) 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()) assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(three.getId())); .hasToString(String.valueOf(three.getId()));
// check in database // check in database
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(3); assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(3);
assertThat(one.isRequiredMigrationStep()).isEqualTo(false); assertThat(one.isRequiredMigrationStep()).isFalse();
assertThat(two.isRequiredMigrationStep()).isEqualTo(false); assertThat(two.isRequiredMigrationStep()).isFalse();
assertThat(three.isRequiredMigrationStep()).isEqualTo(true); assertThat(three.isRequiredMigrationStep()).isTrue();
assertThat(one.getCreatedAt()).isGreaterThanOrEqualTo(current); assertThat(one.getCreatedAt()).isGreaterThanOrEqualTo(current);
assertThat(two.getCreatedAt()).isGreaterThanOrEqualTo(current); assertThat(two.getCreatedAt()).isGreaterThanOrEqualTo(current);
@@ -938,7 +938,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// check repository content // check repository content
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.count()).isEqualTo(0); assertThat(distributionSetManagement.count()).isZero();
} }
@Test @Test

View File

@@ -26,7 +26,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.stream.Collectors;
import io.qameta.allure.Description; import io.qameta.allure.Description;
import io.qameta.allure.Feature; import io.qameta.allure.Feature;
@@ -54,7 +53,7 @@ import org.springframework.test.web.servlet.ResultActions;
@Feature("Component Tests - Management API") @Feature("Component Tests - Management API")
@Story("Distribution Set Tag Resource") @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 String DISTRIBUTIONSETTAGS_ROOT = "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/";
private static final Random RND = new Random(); private static final Random RND = new Random();
@@ -62,7 +61,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Test @Test
@Description("Verifies that a paged result list of DS tags reflects the content on the repository side.") @Description("Verifies that a paged result list of DS tags reflects the content on the repository side.")
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) })
public void getDistributionSetTags() throws Exception { void getDistributionSetTags() throws Exception {
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2); final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
final DistributionSetTag assigned = tags.get(0); final DistributionSetTag assigned = tags.get(0);
final DistributionSetTag unassigned = tags.get(1); final DistributionSetTag unassigned = tags.get(1);
@@ -82,19 +81,16 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Test @Test
@Description("Handles the GET request of retrieving all distribution set tags based by parameter") @Description("Handles the GET request of retrieving all distribution set tags based by parameter")
public void getDistributionSetTagsWithParameters() throws Exception { void getDistributionSetTagsWithParameters() throws Exception {
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2); testdataFactory.createDistributionSetTags(2);
final DistributionSetTag assigned = tags.get(0); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "?limit=10&sort=name:ASC&offset=0&q=name==DsTag"))
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"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
@Test @Test
@Description("Verifies that a paged result list of DS tags reflects the content on the repository side when filtered by distribution set id.") @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<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2); final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
final DistributionSetTag tag1 = tags.get(0); final DistributionSetTag tag1 = tags.get(0);
final DistributionSetTag tag2 = tags.get(1); final DistributionSetTag tag2 = tags.get(1);
@@ -133,7 +129,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Test @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.") @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<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2); final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
final DistributionSetTag tag1 = tags.get(0); final DistributionSetTag tag1 = tags.get(0);
final DistributionSetTag tag2 = tags.get(1); final DistributionSetTag tag2 = tags.get(1);
@@ -162,7 +158,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Test @Test
@Description("Verifies that a single result of a DS tag reflects the content on the repository side.") @Description("Verifies that a single result of a DS tag reflects the content on the repository side.")
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) })
public void getDistributionSetTag() throws Exception { void getDistributionSetTag() throws Exception {
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2); final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(2);
final DistributionSetTag assigned = tags.get(0); final DistributionSetTag assigned = tags.get(0);
@@ -180,7 +176,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Test @Test
@Description("Verifies that created DS tags are stored in the repository as send to the API.") @Description("Verifies that created DS tags are stored in the repository as send to the API.")
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) @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") final Tag tagOne = entityFactory.tag().create().colour("testcol1").description("its a test1").name("thetest1")
.build(); .build();
final Tag tagTwo = entityFactory.tag().create().colour("testcol2").description("its a test2").name("thetest2") final Tag tagTwo = entityFactory.tag().create().colour("testcol2").description("its a test2").name("thetest2")
@@ -212,7 +208,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@ExpectEvents({ @ExpectEvents({
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetTagUpdatedEvent.class, count = 1) }) @Expect(type = DistributionSetTagUpdatedEvent.class, count = 1) })
public void updateDistributionSetTag() throws Exception { void updateDistributionSetTag() throws Exception {
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(1); final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(1);
final DistributionSetTag original = tags.get(0); final DistributionSetTag original = tags.get(0);
@@ -241,7 +237,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@ExpectEvents({ @ExpectEvents({
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetTagDeletedEvent.class, count = 1) }) @Expect(type = DistributionSetTagDeletedEvent.class, count = 1) })
public void deleteDistributionSetTag() throws Exception { void deleteDistributionSetTag() throws Exception {
final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(1); final List<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(1);
final DistributionSetTag original = tags.get(0); final DistributionSetTag original = tags.get(0);
@@ -258,11 +254,11 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetCreatedEvent.class, count = 5),
@Expect(type = DistributionSetUpdatedEvent.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 DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final int setsAssigned = 5; final int setsAssigned = 5;
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); final List<DistributionSet> 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")) mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
@@ -278,12 +274,12 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetCreatedEvent.class, count = 5),
@Expect(type = DistributionSetUpdatedEvent.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 DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final int setsAssigned = 5; final int setsAssigned = 5;
final int limitSize = 1; final int limitSize = 1;
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); final List<DistributionSet> 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") mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize))) .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 = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetCreatedEvent.class, count = 5),
@Expect(type = DistributionSetUpdatedEvent.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 DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final int setsAssigned = 5; final int setsAssigned = 5;
final int offsetParam = 2; final int offsetParam = 2;
final int expectedSize = setsAssigned - offsetParam; final int expectedSize = setsAssigned - offsetParam;
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); final List<DistributionSet> 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") mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)) .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 = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = DistributionSetUpdatedEvent.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 DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final DistributionSet set = testdataFactory.createDistributionSetsWithoutModules(1).get(0); final DistributionSet set = testdataFactory.createDistributionSetsWithoutModules(1).get(0);
@@ -335,8 +331,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andExpect(status().isOk()); .andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) assertThat(updated.stream().map(DistributionSet::getId).toList()).containsOnly(set.getId());
.containsOnly(set.getId());
} }
@Test @Test
@@ -345,20 +340,20 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 2),
@Expect(type = DistributionSetUpdatedEvent.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 DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(2); final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(2);
mvc.perform( mvc.perform(
put(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") 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)) .contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) assertThat(updated.stream().map(DistributionSet::getId).toList())
.containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); .containsAll(sets.stream().map(DistributionSet::getId).toList());
} }
@Test @Test
@@ -367,14 +362,14 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 2),
@Expect(type = DistributionSetUpdatedEvent.class, count = 3) }) @Expect(type = DistributionSetUpdatedEvent.class, count = 3) })
public void unassignDistributionSet() throws Exception { void unassignDistributionSet() throws Exception {
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final int setsAssigned = 2; final int setsAssigned = 2;
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned);
final DistributionSet assigned = sets.get(0); final DistributionSet assigned = sets.get(0);
final DistributionSet unassigned = sets.get(1); 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/" + mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
unassigned.getId())) unassigned.getId()))
@@ -382,7 +377,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andExpect(status().isOk()); .andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); final List<DistributionSet> 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()); .containsOnly(assigned.getId());
} }
@@ -392,14 +387,14 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 3), @Expect(type = DistributionSetCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) @Expect(type = DistributionSetUpdatedEvent.class, count = 5) })
public void unassignDistributionSets() throws Exception { void unassignDistributionSets() throws Exception {
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(3); final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(3);
final DistributionSet assigned = sets.get(0); final DistributionSet assigned = sets.get(0);
final DistributionSet unassigned0 = sets.get(1); final DistributionSet unassigned0 = sets.get(1);
final DistributionSet unassigned1 = sets.get(2); 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") mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.content(JsonBuilder.toArray(List.of(unassigned0.getId(), unassigned1.getId()))) .content(JsonBuilder.toArray(List.of(unassigned0.getId(), unassigned1.getId())))
@@ -408,7 +403,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andExpect(status().isOk()); .andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); final List<DistributionSet> 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()); .containsOnly(assigned.getId());
} }
@@ -417,7 +412,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
@ExpectEvents({ @ExpectEvents({
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 2) }) @Expect(type = DistributionSetCreatedEvent.class, count = 2) })
public void assignDistributionSetsNotFound() throws Exception { void assignDistributionSetsNotFound() throws Exception {
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final List<Long> sets = testdataFactory.createDistributionSetsWithoutModules(2).stream().map(DistributionSet::getId).toList(); final List<Long> sets = testdataFactory.createDistributionSetsWithoutModules(2).stream().map(DistributionSet::getId).toList();
final List<Long> missing = new ArrayList<>(); final List<Long> missing = new ArrayList<>();

View File

@@ -687,13 +687,13 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
assertThat( assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) 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( assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) 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( assertThat(
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) 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); assertThat(distributionSetTypeManagement.count()).isEqualTo(7);
} }

View File

@@ -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.JpaSoftwareModuleCreate;
import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleMetadataCreate; import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleMetadataCreate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants; 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.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
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.SwMetadataCompositeKey;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
@@ -96,6 +96,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
private final VirtualPropertyReplacer virtualPropertyReplacer; private final VirtualPropertyReplacer virtualPropertyReplacer;
private final Database database; private final Database database;
@SuppressWarnings("java:S107")
public JpaSoftwareModuleManagement(final EntityManager entityManager, public JpaSoftwareModuleManagement(final EntityManager entityManager,
final DistributionSetRepository distributionSetRepository, final DistributionSetRepository distributionSetRepository,
final SoftwareModuleRepository softwareModuleRepository, final SoftwareModuleRepository softwareModuleRepository,
@@ -506,8 +507,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
} }
private static Specification<JpaSoftwareModuleMetadata> metadataBySoftwareModuleIdSpec(final long id) { private static Specification<JpaSoftwareModuleMetadata> metadataBySoftwareModuleIdSpec(final long id) {
return (root, query, cb) -> cb return (root, query, cb) -> cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(AbstractJpaBaseEntity_.id), id);
.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), id);
} }
private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) { private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) {

View File

@@ -85,6 +85,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
private final AuditorAware<String> auditorAware; private final AuditorAware<String> auditorAware;
private final Database database; private final Database database;
@SuppressWarnings("java:S107")
public JpaTargetFilterQueryManagement(final TargetFilterQueryRepository targetFilterQueryRepository, public JpaTargetFilterQueryManagement(final TargetFilterQueryRepository targetFilterQueryRepository,
final TargetManagement targetManagement, final VirtualPropertyReplacer virtualPropertyReplacer, final TargetManagement targetManagement, final VirtualPropertyReplacer virtualPropertyReplacer,
final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement, final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement,

View File

@@ -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.JpaTargetCreate;
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetUpdate; import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetUpdate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants; 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.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata;
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 { public class JpaTargetManagement implements TargetManagement {
private final EntityManager entityManager; private final EntityManager entityManager;
private final DistributionSetManagement distributionSetManagement; private final DistributionSetManagement distributionSetManagement;
private final QuotaManagement quotaManagement; private final QuotaManagement quotaManagement;
private final TargetRepository targetRepository; private final TargetRepository targetRepository;
private final TargetTypeRepository targetTypeRepository; private final TargetTypeRepository targetTypeRepository;
private final TargetMetadataRepository targetMetadataRepository; private final TargetMetadataRepository targetMetadataRepository;
private final RolloutGroupRepository rolloutGroupRepository; private final RolloutGroupRepository rolloutGroupRepository;
private final TargetFilterQueryRepository targetFilterQueryRepository; private final TargetFilterQueryRepository targetFilterQueryRepository;
private final TargetTagRepository targetTagRepository; private final TargetTagRepository targetTagRepository;
private final EventPublisherHolder eventPublisherHolder; private final EventPublisherHolder eventPublisherHolder;
private final TenantAware tenantAware; private final TenantAware tenantAware;
private final VirtualPropertyReplacer virtualPropertyReplacer; private final VirtualPropertyReplacer virtualPropertyReplacer;
private final Database database; private final Database database;
@SuppressWarnings("java:S107")
public JpaTargetManagement(final EntityManager entityManager, public JpaTargetManagement(final EntityManager entityManager,
final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement, final DistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement,
final TargetRepository targetRepository, final TargetTypeRepository targetTypeRepository, final TargetRepository targetRepository, final TargetTypeRepository targetTypeRepository,
@@ -875,7 +865,7 @@ public class JpaTargetManagement implements TargetManagement {
} }
private Specification<JpaTargetMetadata> metadataByTargetIdSpec(final Long targetId) { private Specification<JpaTargetMetadata> 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<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams) { private List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams) {

View File

@@ -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.acm.AccessController;
import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate; import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants; 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.model.JpaTargetTag_;
import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository; import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
@@ -93,7 +93,7 @@ public class JpaTargetTagManagement implements TargetTagManagement {
public void delete(final String targetTagName) { public void delete(final String targetTagName) {
targetTagRepository.delete( targetTagRepository.delete(
targetTagRepository 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))); .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagName)));
} }

View File

@@ -217,6 +217,7 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
return targetTypeRepository.save(type); return targetTypeRepository.save(type);
} }
@SuppressWarnings("java:S2201") // the idea is just to check for distribution set type existence
private void assertDistributionSetTypeExists(final Long typeId) { private void assertDistributionSetTypeExists(final Long typeId) {
distributionSetTypeRepository distributionSetTypeRepository
.findById(typeId) .findById(typeId)