Skip to content

Commit

Permalink
Sonar Fix (#2239)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm authored Jan 24, 2025
1 parent ef4c0c6 commit bbb2193
Show file tree
Hide file tree
Showing 37 changed files with 227 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@Feature("Component Tests - Management API")
@Story("Sorting parameter")
public class SortUtilityTest {
class SortUtilityTest {

private static final String SORT_PARAM_1 = "NAME:ASC";
private static final String SORT_PARAM_2 = "NAME:ASC, DESCRIPTION:DESC";
Expand All @@ -38,42 +38,43 @@ public class SortUtilityTest {

@Test
@Description("Ascending sorting based on name.")
public void parseSortParam1() {
void parseSortParam1() {
final List<Order> parse = SortUtility.parse(TargetFields.class, SORT_PARAM_1);
assertThat(parse).as("Count of parsing parameter").hasSize(1);
}

@Test
@Description("Ascending sorting based on name and descending sorting based on description.")
public void parseSortParam2() {
void parseSortParam2() {
final List<Order> parse = SortUtility.parse(TargetFields.class, SORT_PARAM_2);
assertThat(parse).as("Count of parsing parameter").hasSize(2);
}

@Test
@Description("Sorting with wrong syntax leads to SortParameterSyntaxErrorException.")
public void parseWrongSyntaxParam() {
void parseWrongSyntaxParam() {
assertThrows(SortParameterSyntaxErrorException.class,
() -> SortUtility.parse(TargetFields.class, SYNTAX_FAILURE_SORT_PARAM));
}

@Test
@Description("Sorting based on name with case sensitive is possible.")
public void parsingIsNotCaseSensitive() {
@SuppressWarnings("squid:S2699") // assert no error
void parsingIsNotCaseSensitive() {
SortUtility.parse(TargetFields.class, CASE_INSENSITIVE_DIRECTION_PARAM);
SortUtility.parse(TargetFields.class, CASE_INSENSITIVE_DIRECTION_PARAM_1);
}

@Test
@Description("Sorting with unknown direction order leads to SortParameterUnsupportedDirectionException.")
public void parseWrongDirectionParam() {
void parseWrongDirectionParam() {
assertThrows(SortParameterUnsupportedDirectionException.class,
() -> SortUtility.parse(TargetFields.class, WRONG_DIRECTION_PARAM));
}

@Test
@Description("Sorting with unknown field leads to SortParameterUnsupportedFieldException.")
public void parseWrongFieldParam() {
void parseWrongFieldParam() {
assertThrows(SortParameterUnsupportedFieldException.class,
() -> SortUtility.parse(TargetFields.class, WRONG_FIELD_PARAM));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/
package org.eclipse.hawkbit.repository.builder;

import java.util.Optional;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

Expand Down Expand Up @@ -62,8 +60,8 @@ public interface SoftwareModuleCreate {
* @param type for {@link SoftwareModule#getType()}
* @return updated builder instance
*/
default SoftwareModuleCreate type(final SoftwareModuleType type) {
return type(Optional.ofNullable(type).map(SoftwareModuleType::getKey).orElse(null));
default SoftwareModuleCreate type(@NotNull final SoftwareModuleType type) {
return type(type.getKey());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.io.Serial;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -47,8 +46,7 @@ public class TargetAssignDistributionSetEvent extends AbstractAssignmentEvent {
public TargetAssignDistributionSetEvent(final String tenant, final long distributionSetId, final List<Action> a,
final String applicationId, final boolean maintenanceWindowAvailable) {
super(distributionSetId, tenant,
a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId)
.collect(Collectors.toList()),
a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId).toList(),
applicationId);
this.distributionSetId = distributionSetId;
this.maintenanceWindowAvailable = maintenanceWindowAvailable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

import static org.eclipse.hawkbit.repository.SizeConversionHelper.byteValueToReadableString;

import lombok.EqualsAndHashCode;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;

/**
* Thrown if storage quota is exceeded
*/
@EqualsAndHashCode(callSuper = true)
public class StorageQuotaExceededException extends AbstractServerRtException {

private static final String MAX_ARTIFACT_SIZE_TOTAL_EXCEEDED = "Storage quota exceeded, %s left.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import java.util.Collections;
import java.util.List;

import lombok.EqualsAndHashCode;

/**
* Bean for holding the system usage stats including tenant specific data.
*/
@EqualsAndHashCode(callSuper = true)
public class SystemUsageReportWithTenants extends SystemUsageReport {

private final List<TenantUsage> tenants = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ RolloutGroupEvaluationManager evaluationManager(

@Bean
@ConditionalOnMissingBean
SystemManagementCacheKeyGenerator systemManagementCacheKeyGenerator() {
return new SystemManagementCacheKeyGenerator();
SystemManagementCacheKeyGenerator systemManagementCacheKeyGenerator(final TenantAware tenantAware) {
return new SystemManagementCacheKeyGenerator(tenantAware);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
public class SystemManagementCacheKeyGenerator implements CurrentTenantCacheKeyGenerator {

private final ThreadLocal<String> createInitialTenant = new ThreadLocal<>();
@Autowired
private TenantAware tenantAware;
private final TenantAware tenantAware;

public SystemManagementCacheKeyGenerator(final TenantAware tenantAware) {
this.tenantAware = tenantAware;
}

@Override
@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

import jakarta.persistence.criteria.ListJoin;

import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedVersionedEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
Expand All @@ -38,13 +39,13 @@ private SoftwareModuleSpecification() {
* @return the {@link SoftwareModule} {@link Specification}
*/
public static Specification<JpaSoftwareModule> byId(final Long swModuleId) {
return (swRoot, query, cb) -> cb.equal(swRoot.get(JpaSoftwareModule_.id), swModuleId);
return (swRoot, query, cb) -> cb.equal(swRoot.get(AbstractJpaBaseEntity_.id), swModuleId);
}

public static Specification<JpaSoftwareModule> byAssignedToDs(final Long dsId) {
return (swRoot, query, cb) -> {
final ListJoin<JpaSoftwareModule, JpaDistributionSet> join = swRoot.join(JpaSoftwareModule_.assignedTo);
return cb.equal(join.get(JpaDistributionSet_.ID), dsId);
return cb.equal(join.get(AbstractJpaBaseEntity_.ID), dsId);
};
}

Expand All @@ -68,8 +69,8 @@ public static Specification<JpaSoftwareModule> isNotDeleted() {
*/
public static Specification<JpaSoftwareModule> likeNameAndVersion(final String name, final String version) {
return (smRoot, query, cb) -> cb.and(
cb.like(cb.lower(smRoot.get(JpaSoftwareModule_.name)), name.toLowerCase()),
cb.like(cb.lower(smRoot.get(JpaSoftwareModule_.version)), version.toLowerCase()));
cb.like(cb.lower(smRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase()),
cb.like(cb.lower(smRoot.get(AbstractJpaNamedVersionedEntity_.version)), version.toLowerCase()));
}

/**
Expand All @@ -81,7 +82,7 @@ public static Specification<JpaSoftwareModule> likeNameAndVersion(final String n
*/
public static Specification<JpaSoftwareModule> equalType(final Long type) {
return (smRoot, query, cb) -> cb.equal(
smRoot.get(JpaSoftwareModule_.type).get(JpaSoftwareModuleType_.id), type);
smRoot.get(JpaSoftwareModule_.type).get(AbstractJpaBaseEntity_.id), type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.springframework.data.jpa.domain.Specification;
Expand All @@ -42,8 +42,7 @@ public static Specification<JpaDistributionSetTag> ofDistributionSet(final Long

query.distinct(true);

return criteriaBuilder.equal(tagJoin.get(JpaDistributionSet_.id), dsId);
return criteriaBuilder.equal(tagJoin.get(AbstractJpaBaseEntity_.id), dsId);
};

}
}
Loading

0 comments on commit bbb2193

Please sign in to comment.