Skip to content

Commit

Permalink
Sonar Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Jan 27, 2025
1 parent 5cc4372 commit d738d3c
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.qameta.allure.Description;
Expand Down Expand Up @@ -88,7 +87,7 @@ void verifyConfirmationReferencesInControllerBase(@Autowired ActionStatusReposit
final List<Target> targetsAssignedToDs = assignDistributionSet(
ds.getId(), savedTarget.getControllerId(), Action.ActionType.FORCED).getAssignedEntity().stream()
.map(Action::getTarget)
.collect(Collectors.toList());
.toList();
implicitLock(ds);

assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import com.jayway.jsonpath.JsonPath;
import io.qameta.allure.Description;
Expand Down Expand Up @@ -151,7 +150,7 @@ void deploymentForceAction() throws Exception {
final List<Target> targetsAssignedToDs = assignDistributionSet(ds.getId(), savedTarget.getControllerId(), ActionType.FORCED)
.getAssignedEntity().stream()
.map(Action::getTarget)
.collect(Collectors.toList());
.toList();
implicitLock(ds);

assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1);
Expand Down Expand Up @@ -252,7 +251,7 @@ void deploymentAttemptAction() throws Exception {
final Target savedTarget = createTargetAndAssertNoActiveActions();

final List<Target> saved = assignDistributionSet(ds.getId(), savedTarget.getControllerId(), ActionType.SOFT)
.getAssignedEntity().stream().map(Action::getTarget).collect(Collectors.toList());
.getAssignedEntity().stream().map(Action::getTarget).toList();
implicitLock(ds);
assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1);

Expand Down Expand Up @@ -307,7 +306,7 @@ void deploymentAutoForceAction() throws Exception {
final Target savedTarget = createTargetAndAssertNoActiveActions();

final List<Target> saved = assignDistributionSet(ds.getId(), savedTarget.getControllerId(),
ActionType.TIMEFORCED).getAssignedEntity().stream().map(Action::getTarget).collect(Collectors.toList());
ActionType.TIMEFORCED).getAssignedEntity().stream().map(Action::getTarget).toList();
implicitLock(ds);
assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1);

Expand Down Expand Up @@ -371,7 +370,7 @@ void deploymentDownloadOnlyAction() throws Exception {
final List<Target> saved = assignDistributionSet(ds.getId(), savedTarget.getControllerId(), ActionType.DOWNLOAD_ONLY)
.getAssignedEntity().stream()
.map(Action::getTarget)
.collect(Collectors.toList());
.toList();
implicitLock(ds);
assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import jakarta.persistence.EntityManager;

Expand Down Expand Up @@ -49,7 +48,6 @@
import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -173,8 +171,7 @@ private DistributionSetTagAssignmentResult toggleDistributionSetTagAssignment(fi
.findByName(tagName)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName)),
(allDs, distributionSetTag) -> {
final List<JpaDistributionSet> toBeChangedDSs = allDs.stream().filter(set -> set.addTag(distributionSetTag))
.collect(Collectors.toList());
final List<JpaDistributionSet> toBeChangedDSs = allDs.stream().filter(set -> set.addTag(distributionSetTag)).toList();

final DistributionSetTagAssignmentResult result;
// un-assignment case
Expand All @@ -186,13 +183,11 @@ private DistributionSetTagAssignmentResult toggleDistributionSetTagAssignment(fi
}
result = new DistributionSetTagAssignmentResult(ids.size() - toBeChangedDSs.size(),
Collections.emptyList(),
Collections.unmodifiableList(
toBeChangedDSs.stream().map(distributionSetRepository::save).toList()),
toBeChangedDSs.stream().map(distributionSetRepository::save).map(DistributionSet.class::cast).toList(),
distributionSetTag);
} else {
result = new DistributionSetTagAssignmentResult(ids.size() - toBeChangedDSs.size(),
Collections.unmodifiableList(
toBeChangedDSs.stream().map(distributionSetRepository::save).toList()),
toBeChangedDSs.stream().map(distributionSetRepository::save).map(DistributionSet.class::cast).toList(),
Collections.emptyList(), distributionSetTag);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public ResponseEntity<MgmtTargetAssignmentResponseBody> postAssignedDistribution
final String targetId, final MgmtDistributionSetAssignments dsAssignments, final Boolean offline) {
if (offline != null && offline) {
final List<Entry<String, Long>> offlineAssignments = dsAssignments.stream()
.map(dsAssignment -> new SimpleEntry<String, Long>(targetId, dsAssignment.getId()))
.map(dsAssignment -> new SimpleEntry<>(targetId, dsAssignment.getId()))
.collect(Collectors.toList());
return ResponseEntity.ok(MgmtDistributionSetMapper
.toResponse(deploymentManagement.offlineAssignedDistributionSets(offlineAssignments)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import io.qameta.allure.Description;
import io.qameta.allure.Feature;
Expand Down Expand Up @@ -612,7 +611,7 @@ private List<Action> generateTargetWithTwoUpdatesWithOneOverrideWithMaintenanceW
// Update
if (schedule == null) {
final List<Target> updatedTargets = assignDistributionSet(one, Collections.singletonList(target))
.getAssignedEntity().stream().map(Action::getTarget).collect(Collectors.toList());
.getAssignedEntity().stream().map(Action::getTarget).toList();
// 2nd update
// sleep 10ms to ensure that we can sort by reportedAt
Awaitility.await().atMost(Duration.ofMillis(100)).atLeast(5, TimeUnit.MILLISECONDS)
Expand All @@ -622,7 +621,7 @@ private List<Action> generateTargetWithTwoUpdatesWithOneOverrideWithMaintenanceW
} else {
final List<Target> updatedTargets = assignDistributionSetWithMaintenanceWindow(one.getId(),
target.getControllerId(), schedule, duration, timezone).getAssignedEntity().stream()
.map(Action::getTarget).collect(Collectors.toList());
.map(Action::getTarget).toList();
// 2nd update
// sleep 10ms to ensure that we can sort by reportedAt
Awaitility.await().atMost(Duration.ofMillis(100)).atLeast(5, TimeUnit.MILLISECONDS)
Expand Down
Loading

0 comments on commit d738d3c

Please sign in to comment.