Sonar Fixes (#2240)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-27 11:45:14 +02:00
committed by GitHub
parent cbadd4c249
commit c766fd76da
24 changed files with 374 additions and 346 deletions

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.jpa;
import java.lang.reflect.Method;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Service;
@@ -22,12 +21,14 @@ import org.springframework.stereotype.Service;
@Service
public class TenantKeyGenerator implements KeyGenerator {
@Autowired
private TenantAware tenantAware;
private final TenantAware tenantAware;
public TenantKeyGenerator(final TenantAware tenantAware) {
this.tenantAware = tenantAware;
}
@Override
public Object generate(final Object target, final Method method, final Object... params) {
return tenantAware.getCurrentTenant().toUpperCase();
}
}
}

View File

@@ -13,7 +13,6 @@ import java.util.List;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
import org.eclipse.hawkbit.repository.jpa.specifications.TargetTypeSpecification;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

View File

@@ -15,8 +15,10 @@ import jakarta.persistence.criteria.SetJoin;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTypeEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType_;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -36,7 +38,7 @@ public final class TargetTypeSpecification {
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> hasIdIn(final Collection<Long> ids) {
return (targetRoot, query, cb) -> targetRoot.get(JpaTargetType_.id).in(ids);
return (targetRoot, query, cb) -> targetRoot.get(AbstractJpaBaseEntity_.id).in(ids);
}
/**
@@ -48,32 +50,28 @@ public final class TargetTypeSpecification {
public static Specification<JpaTargetType> hasDsSetType(final Long dsTypeId) {
return (targetRoot, query, cb) -> {
final SetJoin<JpaTargetType, JpaDistributionSetType> join = targetRoot.join(JpaTargetType_.distributionSetTypes);
return cb.equal(join.get(JpaDistributionSetType_.id), dsTypeId);
return cb.equal(join.get(AbstractJpaBaseEntity_.id), dsTypeId);
};
}
/**
* {@link Specification} for retrieving {@link TargetType} with
* given {@link TargetType#getKey()} including fetching the
* elements list.
* {@link Specification} for retrieving {@link TargetType} with given {@link TargetType#getKey()} including fetching the elements list.
*
* @param key to search
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> hasKey(final String key) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTargetType_.key), key);
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(AbstractJpaTypeEntity_.key), key);
}
/**
* {@link Specification} for retrieving {@link TargetType} with
* given {@link TargetType#getName()} including fetching the
* elements list.
* {@link Specification} for retrieving {@link TargetType} with given {@link TargetType#getName()} including fetching the elements list.
*
* @param name to search
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> hasName(final String name) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTargetType_.name), name);
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(AbstractJpaNamedEntity_.name), name);
}
/**
@@ -83,6 +81,6 @@ public final class TargetTypeSpecification {
* @return the {@link TargetType} {@link Specification}
*/
public static Specification<JpaTargetType> likeName(final String name) {
return (targetRoot, query, cb) -> cb.like(cb.lower(targetRoot.get(JpaTargetType_.name)), name.toLowerCase());
return (targetRoot, query, cb) -> cb.like(cb.lower(targetRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase());
}
}

View File

@@ -108,11 +108,11 @@ public final class WeightValidationHelper {
* @param hasNoWeight indicator of the weight if it doesn't have a numerical value
*/
public void validateWeight(final boolean hasWeight, final boolean hasNoWeight) {
// remove bypassing the weight enforcement as soon as weight can be set
// via UI
// remove bypassing the weight enforcement as soon as weight can be set via UI
final boolean bypassWeightEnforcement = true;
final boolean multiAssignmentsEnabled = TenantConfigHelper
.usingContext(systemSecurityContext, tenantConfigurationManagement).isMultiAssignmentsEnabled();
.usingContext(systemSecurityContext, tenantConfigurationManagement)
.isMultiAssignmentsEnabled();
if (bypassWeightEnforcement) {
return;
} else if (multiAssignmentsEnabled && hasNoWeight) {