Sonar Fixes (#2233)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-24 15:41:06 +02:00
committed by GitHub
parent 0280d96d2c
commit a61e9cd6ae
66 changed files with 401 additions and 387 deletions

View File

@@ -16,7 +16,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;

View File

@@ -37,10 +37,13 @@ import org.springframework.web.context.WebApplicationContext;
@Scope(value = WebApplicationContext.SCOPE_REQUEST)
public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi {
@Autowired
private SoftwareModuleManagement softwareModuleManagement;
@Autowired
private ArtifactManagement artifactManagement;
private final SoftwareModuleManagement softwareModuleManagement;
private final ArtifactManagement artifactManagement;
public MgmtDownloadArtifactResource(final SoftwareModuleManagement softwareModuleManagement, final ArtifactManagement artifactManagement) {
this.softwareModuleManagement = softwareModuleManagement;
this.artifactManagement = artifactManagement;
}
/**
* Handles the GET request for downloading an artifact.

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -68,7 +67,7 @@ final class MgmtRolloutMapper {
return Collections.emptyList();
}
return rollouts.stream().map(rollout -> toResponseRollout(rollout, withDetails)).collect(Collectors.toList());
return rollouts.stream().map(rollout -> toResponseRollout(rollout, withDetails)).toList();
}
static MgmtRolloutResponseBody toResponseRollout(final Rollout rollout, final boolean withDetails) {
@@ -200,14 +199,13 @@ final class MgmtRolloutMapper {
return conditions.build();
}
static List<MgmtRolloutGroupResponseBody> toResponseRolloutGroup(final List<RolloutGroup> rollouts,
final boolean confirmationFlowEnabled, final boolean withDetails) {
static List<MgmtRolloutGroupResponseBody> toResponseRolloutGroup(
final List<RolloutGroup> rollouts, final boolean confirmationFlowEnabled, final boolean withDetails) {
if (rollouts == null) {
return Collections.emptyList();
}
return rollouts.stream().map(group -> toResponseRolloutGroup(group, withDetails, confirmationFlowEnabled))
.collect(Collectors.toList());
return rollouts.stream().map(group -> toResponseRolloutGroup(group, withDetails, confirmationFlowEnabled)).toList();
}
static MgmtRolloutGroupResponseBody toResponseRolloutGroup(final RolloutGroup rolloutGroup,

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import jakarta.validation.ValidationException;
@@ -147,7 +146,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
rolloutRequestBody).orElse(confirmationFlowActive);
return MgmtRolloutMapper.fromRequest(entityFactory, mgmtRolloutGroup)
.confirmationRequired(confirmationRequired);
}).collect(Collectors.toList());
}).toList();
rollout = rolloutManagement.create(create, rolloutGroups, rolloutGroupConditions);
} else if (rolloutRequestBody.getAmountGroups() != null) {
final boolean confirmationRequired = rolloutRequestBody.getConfirmationRequired() == null

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -57,7 +56,7 @@ public final class MgmtSoftwareModuleMapper {
.map(metadataRest -> entityFactory.softwareModuleMetadata().create(softwareModuleId)
.key(metadataRest.getKey()).value(metadataRest.getValue())
.targetVisible(metadataRest.isTargetVisible()))
.collect(Collectors.toList());
.toList();
}
static List<SoftwareModuleCreate> smFromRequest(final EntityFactory entityFactory,
@@ -66,7 +65,7 @@ public final class MgmtSoftwareModuleMapper {
return Collections.emptyList();
}
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList());
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
}
static List<MgmtSoftwareModule> toResponse(final Collection<SoftwareModule> softwareModules) {
@@ -74,8 +73,7 @@ public final class MgmtSoftwareModuleMapper {
return Collections.emptyList();
}
return new ResponseList<>(
softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList()));
return new ResponseList<>(softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).toList());
}
static List<MgmtSoftwareModuleMetadata> toResponseSwMetadata(final Collection<SoftwareModuleMetadata> metadata) {
@@ -83,7 +81,7 @@ public final class MgmtSoftwareModuleMapper {
return Collections.emptyList();
}
return metadata.stream().map(MgmtSoftwareModuleMapper::toResponseSwMetadata).collect(Collectors.toList());
return metadata.stream().map(MgmtSoftwareModuleMapper::toResponseSwMetadata).toList();
}
static MgmtSoftwareModuleMetadata toResponseSwMetadata(final SoftwareModuleMetadata metadata) {

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -39,7 +38,7 @@ final class MgmtSoftwareModuleTypeMapper {
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<MgmtSoftwareModuleType> toTypesResponse(final Collection<SoftwareModuleType> types) {
@@ -47,7 +46,7 @@ final class MgmtSoftwareModuleTypeMapper {
return Collections.emptyList();
}
return new ResponseList<>(types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).collect(Collectors.toList()));
return new ResponseList<>(types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).toList());
}
static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) {

View File

@@ -70,8 +70,7 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
.setOverallArtifactVolumeInBytes(report.getOverallArtifactVolumeInBytes())
.setOverallTargets(report.getOverallTargets()).setOverallTenants(report.getTenants().size());
result.setTenantStats(report.getTenants().stream().map(MgmtSystemManagementResource::convertTenant)
.collect(Collectors.toList()));
result.setTenantStats(report.getTenants().stream().map(MgmtSystemManagementResource::convertTenant).toList());
return ResponseEntity.ok(result);
}
@@ -89,7 +88,7 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
.ok(cacheNames.stream().map(cacheManager::getCache)
.filter(Objects::nonNull)
.map(cache -> new MgmtSystemCache(cache.getName(), Collections.emptyList()))
.collect(Collectors.toList()));
.toList());
}
/**

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -111,7 +110,7 @@ final class MgmtTagMapper {
return tags.stream()
.map(tagRest -> entityFactory.tag().create().name(tagRest.getName())
.description(tagRest.getDescription()).colour(tagRest.getColour()))
.collect(Collectors.toList());
.toList();
}
private static void mapTag(final MgmtTag response, final Tag tag) {

View File

@@ -38,12 +38,12 @@ import org.springframework.util.CollectionUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTargetFilterQueryMapper {
static List<MgmtTargetFilterQuery> toResponse(final List<TargetFilterQuery> filters,
final boolean confirmationFlowEnabled, final boolean isRepresentationFull) {
static List<MgmtTargetFilterQuery> toResponse(
final List<TargetFilterQuery> filters, final boolean confirmationFlowEnabled, final boolean isRepresentationFull) {
if (CollectionUtils.isEmpty(filters)) {
return Collections.emptyList();
}
return filters.stream().map(filter -> toResponse(filter, confirmationFlowEnabled, isRepresentationFull)).collect(Collectors.toList());
return filters.stream().map(filter -> toResponse(filter, confirmationFlowEnabled, isRepresentationFull)).toList();
}
static MgmtTargetFilterQuery toResponse(final TargetFilterQuery filter, final boolean confirmationFlowEnabled,

View File

@@ -19,7 +19,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -124,7 +123,7 @@ public final class MgmtTargetMapper {
final Function<Target, PollStatus> pollStatusResolver = configHelper.pollStatusResolver();
return new ResponseList<>(
targets.stream().map(target -> toResponse(target, configHelper, pollStatusResolver)).collect(Collectors.toList()));
targets.stream().map(target -> toResponse(target, configHelper, pollStatusResolver)).toList());
}
/**
@@ -194,7 +193,7 @@ public final class MgmtTargetMapper {
}
return targetsRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest))
.collect(Collectors.toList());
.toList();
}
static List<MetaData> fromRequestTargetMetadata(final List<MgmtMetadata> metadata,
@@ -205,7 +204,7 @@ public final class MgmtTargetMapper {
return metadata.stream().map(
metadataRest -> entityFactory.generateTargetMetadata(metadataRest.getKey(), metadataRest.getValue()))
.collect(Collectors.toList());
.toList();
}
static List<MgmtActionStatus> toActionStatusRestResponse(final Collection<ActionStatus> actionStatus,
@@ -219,7 +218,7 @@ public final class MgmtTargetMapper {
deploymentManagement.findMessagesByActionStatusId(
PageRequest.of(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), status.getId())
.getContent()))
.collect(Collectors.toList());
.toList();
}
static MgmtAction toResponse(final String targetId, final Action action) {
@@ -317,7 +316,7 @@ public final class MgmtTargetMapper {
}
static List<MgmtMetadata> toResponseTargetMetadata(final List<TargetMetadata> metadata) {
return metadata.stream().map(MgmtTargetMapper::toResponseTargetMetadata).collect(Collectors.toList());
return metadata.stream().map(MgmtTargetMapper::toResponseTargetMetadata).toList();
}
private static void addPollStatus(final Target target, final MgmtTarget targetRest, final Function<Target, PollStatus> pollStatusResolver) {

View File

@@ -137,7 +137,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<MgmtTarget> updateTarget(final String targetId, final MgmtTargetRequestBody targetRest) {
if (targetRest.getRequestAttributes() != null) {
if (targetRest.getRequestAttributes()) {
if (Boolean.TRUE.equals(targetRest.getRequestAttributes())) {
targetManagement.requestControllerAttributes(targetId);
} else {
return ResponseEntity.badRequest().build();
@@ -336,7 +336,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
: dsAssignment.getConfirmationRequired();
return MgmtDeploymentRequestMapper.createAssignmentRequestBuilder(dsAssignment, targetId)
.setConfirmationRequired(isConfirmationRequired).build();
}).collect(Collectors.toList());
}).toList();
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
.assignDistributionSets(deploymentRequests);

View File

@@ -157,11 +157,9 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
} else {
final AtomicReference<Collection<String>> notFound = new AtomicReference<>();
this.targetManagement.assignTag(controllerIds, targetTagId, notFound::set);
if (notFound.get() != null) {
// has not found
if (onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
throw new EntityNotFoundException(Target.class, notFound.get());
} // else - success
if (notFound.get() != null && onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
// has not found and ON_WHAT_FOUND_AND_FAIL
throw new EntityNotFoundException(Target.class, notFound.get());
}
}
return ResponseEntity.ok().build();
@@ -183,11 +181,9 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
} else {
final AtomicReference<Collection<String>> notFound = new AtomicReference<>();
this.targetManagement.unassignTag(controllerIds, targetTagId, notFound::set);
if (notFound.get() != null) {
// has not found
if (onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
throw new EntityNotFoundException(Target.class, notFound.get());
} // else - success
if (notFound.get() != null && onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
// has not found and ON_WHAT_FOUND_AND_FAIL
throw new EntityNotFoundException(Target.class, notFound.get());
}
}
return ResponseEntity.ok().build();

View File

@@ -16,7 +16,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -43,14 +42,14 @@ public final class MgmtTargetTypeMapper {
}
return targetTypesRest.stream()
.map(targetRest -> fromRequest(entityFactory, targetRest))
.collect(Collectors.toList());
.toList();
}
static List<MgmtTargetType> toListResponse(final List<TargetType> types) {
if (types == null) {
return Collections.emptyList();
}
return new ResponseList<>(types.stream().map(MgmtTargetTypeMapper::toResponse).collect(Collectors.toList()));
return new ResponseList<>(types.stream().map(MgmtTargetTypeMapper::toResponse).toList());
}
static MgmtTargetType toResponse(final TargetType type) {
@@ -78,7 +77,7 @@ public final class MgmtTargetTypeMapper {
private static Collection<Long> getDistributionSets(final MgmtTargetTypeRequestBodyPost targetTypesRest) {
return Optional.ofNullable(targetTypesRest.getCompatibledistributionsettypes())
.map(ds -> ds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()))
.map(ds -> ds.stream().map(MgmtDistributionSetTypeAssignment::getId).toList())
.orElse(Collections.emptyList());
}
}
}

View File

@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTenantManagementMapper {
public static String DEFAULT_DISTRIBUTION_SET_TYPE_KEY = "default.ds.type";
public static final String DEFAULT_DISTRIBUTION_SET_TYPE_KEY = "default.ds.type";
public static MgmtSystemTenantConfigurationValue toResponseTenantConfigurationValue(
final String key, final TenantConfigurationValue<?> repoConfValue) {